Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

javascript-stringify

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

javascript-stringify - npm Package Compare versions

Comparing version 1.6.0 to 2.0.0

dist/array.d.ts

66

package.json
{
"name": "javascript-stringify",
"version": "1.6.0",
"version": "2.0.0",
"description": "Stringify is to `eval` as `JSON.stringify` is to `JSON.parse`",
"main": "javascript-stringify.js",
"typings": "javascript-stringify.d.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"javascript-stringify.js",
"javascript-stringify.d.ts"
"dist/"
],
"scripts": {
"test": "istanbul cover node_modules/mocha/bin/_mocha -- -R spec"
"prettier": "prettier --write",
"format": "npm run prettier -- \"{.,src/**}/*.{js,ts,json,md,yml,css}\"",
"lint": "tslint \"src/**/*.ts\" --project tsconfig.json",
"build": "rimraf dist/ && tsc",
"specs": "jest --coverage",
"test": "npm run lint && npm run build && npm run specs",
"prepare": "npm run build"
},

@@ -19,3 +24,5 @@ "repository": "https://github.com/blakeembrey/javascript-stringify.git",

"object",
"string"
"eval",
"string",
"code"
],

@@ -28,8 +35,45 @@ "author": {

"license": "MIT",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/blakeembrey/javascript-stringify/issues"
},
"homepage": "https://github.com/blakeembrey/javascript-stringify",
"jest": {
"roots": [
"<rootDir>/src/"
],
"transform": {
"\\.tsx?$": "ts-jest"
}
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,ts,json,md,yml,css}": [
"npm run prettier",
"git add"
]
},
"publishConfig": {
"access": "public"
},
"devDependencies": {
"chai": "^1.9.1",
"istanbul": "^0.3.0",
"mocha": "^1.21.3"
"@types/jest": "^24.0.9",
"@types/node": "^11.10.4",
"@types/semver": "^5.5.0",
"fast-check": "^1.12.0",
"husky": "^1.3.1",
"jest": "^24.0.0",
"lint-staged": "^8.1.1",
"prettier": "^1.16.1",
"rimraf": "^2.5.4",
"semver": "^5.6.0",
"ts-jest": "^24.0.0",
"tslint": "^5.0.0",
"tslint-config-prettier": "^1.17.0",
"tslint-config-standard": "^8.0.0",
"typescript": "^3.3.1"
}
}

69

README.md

@@ -12,53 +12,38 @@ # JavaScript Stringify

```javascript
```
npm install javascript-stringify --save
bower install javascript-stringify --save
```
### Node
---
```javascript
var javascriptStringify = require('javascript-stringify');
```
<a href="https://www.buymeacoffee.com/blakeembrey" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" ></a>
### AMD
```javascript
define(function (require, exports, module) {
var javascriptStringify = require('javascript-stringify');
});
```
### `<script>` tag
```html
<script src="javascript-stringify.js"></script>
```
## Usage
```javascript
javascriptStringify(value[, replacer [, space [, options]]])
import { stringify } from "javascript-stringify";
```
The API is similar to `JSON.stringify`. However, any value returned by the replacer will be used literally. For this reason, the replacer is passed three arguments - `value`, `indentation` and `stringify`. If you need to continue the stringification process inside your replacer, you can call `stringify(value)` with the new value.
The API is similar `JSON.stringify`:
The `options` object allows some additional configuration:
- `value` The value to convert to a string
- `replacer` A function that alters the behavior of the stringification process
- `space` A string or number that's used to insert white space into the output for readability purposes
- `options`
- **maxDepth** _(number, default: 100)_ The maximum depth of values to stringify
- **maxValues** _(number, default: 100000)_ The maximum number of values to stringify
- **references** _(boolean, default: false)_ Restore circular/repeated references in the object (uses IIFE)
- **skipUndefinedProperties** _(boolean, default: false)_ Omits `undefined` properties instead of restoring as `undefined`
* **maxDepth** _(number, default: 100)_ The maximum depth of values to stringify
* **maxValues** _(number, default: 100000)_ The maximum number of values to stringify
* **references** _(boolean, default: false)_ Restore circular/repeated references in the object (uses IIFE)
* **skipUndefinedProperties** _(boolean, default: false)_ Omits `undefined` properties instead of restoring as `undefined`
### Examples
```javascript
javascriptStringify({}); // "{}"
javascriptStringify(true); // "true"
javascriptStringify('foo'); // "'foo'"
stringify({}); // "{}"
stringify(true); // "true"
stringify("foo"); // "'foo'"
javascriptStringify({ x: 5, y: 6}); // "{x:5,y:6}"
javascriptStringify([1, 2, 3, 'string']); // "[1,2,3,'string']"
stringify({ x: 5, y: 6 }); // "{x:5,y:6}"
stringify([1, 2, 3, "string"]); // "[1,2,3,'string']"
javascriptStringify({ a: { b: { c: 1 } } }, null, null, { maxDepth: 2 }); // "{a:{b:{}}}"
stringify({ a: { b: { c: 1 } } }, null, null, { maxDepth: 2 }); // "{a:{b:{}}}"

@@ -69,3 +54,3 @@ /**

javascriptStringify({ 'some-key': 10 }); // "{'some-key':10}"
stringify({ "some-key": 10 }); // "{'some-key':10}"

@@ -76,3 +61,3 @@ /**

javascriptStringify([/.+/ig, new Number(10), new Date()]); // "[/.+/gi,new Number(10),new Date(1406623295732)]"
stringify([/.+/gi, new Number(10), new Date()]); // "[/.+/gi,new Number(10),new Date(1406623295732)]"

@@ -86,4 +71,4 @@ /**

javascriptStringify(obj); // "{x:10}"
javascriptStringify(obj, null, null, { references: true }); // "(function(){var x={x:10};x.circular=x;return x;}())"
stringify(obj); // "{x:10}"
stringify(obj, null, null, { references: true }); // "(function(){var x={x:10};x.circular=x;return x;}())"

@@ -94,4 +79,4 @@ /**

javascriptStringify({ a: 2 }, null, ' '); // "{\n a: 2\n}"
javascriptStringify({ uno: 1, dos : 2 }, null, '\t'); // "{\n\tuno: 1,\n\tdos: 2\n}"
stringify({ a: 2 }, null, " "); // "{\n a: 2\n}"
stringify({ uno: 1, dos: 2 }, null, "\t"); // "{\n\tuno: 1,\n\tdos: 2\n}"

@@ -102,4 +87,4 @@ /**

javascriptStringify(['test', 'string'], function (value, indent, stringify) {
if (typeof value === 'string') {
stringify(["test", "string"], function(value, indent, stringify) {
if (typeof value === "string") {
return '"' + value.replace(/"/g, '\\"') + '"';

@@ -106,0 +91,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc