npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stringify-with-filter

v1.0.2

Published

Translate a JavaScript object or array into a formatted string, only outputting the properties within the whitelist or exclude blacklist.

Downloads

4

Readme

stringifyWithWhitelist

  • This npm package provides a method called stringifyWithWhitelist that allows you to convert a JavaScript object into a string, but only includes key paths in a whitelist. This method marks circular references with "[Circular]" when dealing with objects containing circular references.

Installation

  • Install this package using npm:
npm install stringify-with-whitelist

Usage

  • First, import the stringifyWithWhitelist and stringifyWithBlacklist method:
const { stringifyWithWhitelist,stringifyWithBlacklist } = require('stringify-with-whitelist');

Then, you can pass any JavaScript object to the stringifyWithWhitelist method and provide an array containing whitelist key paths so that only these paths are included when converting to a string.

Copy code
const obj = {
  a: {
    b: {
      c: 1,
      d: 2
    },
    e: 3
  },
  f: [4, 5, 6]
};

const whitelist = ['a.b.c', 'a.e', 'f.*'];

const result = stringifyWithWhitelist(obj, whitelist);
console.log(result);

Output

css
{
  a: {
    b: {
      c: 1
    },
    e: 3
  },
  f: [
    4,
    5,
    6
  ]
}

API

  • stringifyWithWhitelist(obj, whitelist)
    • obj (Object): The JavaScript object to be converted into a string.
    • whitelist (Array): An array of strings containing the key paths to be included in the output. Use an asterisk () to represent array elements. Examples: 'a.b.c', 'f.'. Return value: A string representing the JavaScript object filtered through the whitelist.

Note: This method marks circular references with "[Circular]" when dealing with objects containing circular references.

Contributions

  • If you would like to contribute to this project, please see the code repository on GitHub for more details.

License

  • This software is released under the MIT License. For more information, please refer to the LICENSE file.

stringifyWithWhitelist

  • 这个npm包提供了一个名为stringifyWithWhitelist的方法,它可以让您将一个JavaScript对象转换成一个字符串,但只包括在白名单中的键路径。这个方法在处理包含循环引用的对象时,会用"[Circular]"标记循环引用。

安装

  • 使用npm安装此包:
npm install stringify-with-whitelist

使用

  • 首先,导入stringifyWithWhitelist方法:
const { stringifyWithWhitelist } = require('stringify-with-whitelist');

然后,您可以将任意JavaScript对象传递给stringifyWithWhitelist方法,并提供一个包含白名单键路径的数组,以便在转换为字符串时仅包含这些路径。

Copy code
const obj = {
  a: {
    b: {
      c: 1,
      d: 2
    },
    e: 3
  },
  f: [4, 5, 6]
};

const whitelist = ['a.b.c', 'a.e', 'f.*'];

const result = stringifyWithWhitelist(obj, whitelist);
console.log(result);
输出:

css
Copy code
{
  a: {
    b: {
      c: 1
    },
    e: 3
  },
  f: [
    4,
    5,
    6
  ]
}

API

  • stringifyWithWhitelist(obj, whitelist)
    • obj (Object): 要转换为字符串的JavaScript对象。
    • whitelist (Array): 字符串数组,包含要包含在输出中的键路径。使用星号 () 表示数组元素。例如:'a.b.c', 'f.'。 返回值:一个字符串,表示经过白名单过滤的JavaScript对象。

注意:此方法在处理包含循环引用的对象时,会用"[Circular]"标记循环引用。

贡献

  • 如果您想为此项目做出贡献,请查看GitHub上的代码库以获取详细信息。

许可证

  • 此软件在MIT许可证下发布。有关详细信息,请参阅LICENSE文件。