Gathering detailed insights and metrics for javascript-stringify
Gathering detailed insights and metrics for javascript-stringify
Gathering detailed insights and metrics for javascript-stringify
Gathering detailed insights and metrics for javascript-stringify
Stringify is to `eval` as `JSON.stringify` is to `JSON.parse`
npm install javascript-stringify
Use `Buffer.from`
Published on 14 Apr 2021
Custom Function Properties
Published on 05 Nov 2019
ESNext Function Syntaxes + TypeScript
Published on 06 Mar 2019
Handle `Error`, `Map` and `Set`
Published on 23 Feb 2017
Skip Undefined Properties
Published on 02 Nov 2016
Max Values
Published on 19 Aug 2016
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
140 Stars
81 Commits
16 Forks
5 Watching
1 Branches
8 Contributors
Updated on 29 Sept 2024
TypeScript (100%)
Cumulative downloads
Total Downloads
Last day
-4.1%
403,676
Compared to previous day
Last week
2.7%
2,294,433
Compared to previous week
Last month
12.4%
9,416,664
Compared to previous month
Last year
3.5%
97,061,238
Compared to previous year
Stringify is to
eval
asJSON.stringify
is toJSON.parse
.
npm install javascript-stringify --save
1import { stringify } from "javascript-stringify";
The API is similar JSON.stringify
:
value
The value to convert to a stringreplacer
A function that alters the behavior of the stringification processspace
A string or number that's used to insert white space into the output for readability purposesoptions
undefined
properties instead of restoring as undefined
1stringify({}); // "{}" 2stringify(true); // "true" 3stringify("foo"); // "'foo'" 4 5stringify({ x: 5, y: 6 }); // "{x:5,y:6}" 6stringify([1, 2, 3, "string"]); // "[1,2,3,'string']" 7 8stringify({ a: { b: { c: 1 } } }, null, null, { maxDepth: 2 }); // "{a:{b:{}}}" 9 10/** 11 * Invalid key names are automatically stringified. 12 */ 13stringify({ "some-key": 10 }); // "{'some-key':10}" 14 15/** 16 * Some object types and values can remain identical. 17 */ 18stringify([/.+/gi, new Number(10), new Date()]); // "[/.+/gi,new Number(10),new Date(1406623295732)]" 19 20/** 21 * Unknown or circular references are removed. 22 */ 23var obj = { x: 10 }; 24obj.circular = obj; 25 26stringify(obj); // "{x:10}" 27stringify(obj, null, null, { references: true }); // "(function(){var x={x:10};x.circular=x;return x;}())" 28 29/** 30 * Specify indentation - just like `JSON.stringify`. 31 */ 32stringify({ a: 2 }, null, " "); // "{\n a: 2\n}" 33stringify({ uno: 1, dos: 2 }, null, "\t"); // "{\n\tuno: 1,\n\tdos: 2\n}" 34 35/** 36 * Add custom replacer behaviour - like double quoted strings. 37 */ 38stringify(["test", "string"], function (value, indent, stringify) { 39 if (typeof value === "string") { 40 return '"' + value.replace(/"/g, '\\"') + '"'; 41 } 42 43 return stringify(value); 44}); 45//=> '["test","string"]'
You can use your own code formatter on the result of javascript-stringify
. Here is an example using eslint:
1const { CLIEngine } = require("eslint"); 2const { stringify } = require("javascript-stringify"); 3 4const { APP_ROOT_PATH, ESLINTRC_FILE_PATH } = require("./constants"); 5 6const ESLINT_CLI = new CLIEngine({ 7 fix: true, 8 cwd: APP_ROOT_PATH, 9 configFile: ESLINTRC_FILE_PATH, 10}); 11 12module.exports = (objectToStringify) => { 13 return ESLINT_CLI.executeOnText(stringify(objectToStringify)).results[0] 14 .output; 15};
MIT
No vulnerabilities found.
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
project is fuzzed
Details
Reason
Found 6/25 approved changesets -- score normalized to 2
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
21 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More