Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Commit 120efdd

Browse files
committed
Update README
1 parent 9d7067a commit 120efdd

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

README.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,43 @@
44
[![Coverage Status](https://coveralls.io/repos/github/tuftjs/json-stringify/badge.svg?branch=master)](https://coveralls.io/github/tuftjs/json-stringify?branch=master)
55
[![Known Vulnerabilities](https://snyk.io/test/github/tuftjs/json-stringify/badge.svg?targetFile=package.json)](https://snyk.io/test/github/tuftjs/json-stringify?targetFile=package.json)
66

7-
A JSON library for Node.js that exports the following functions:
7+
A JSON library for Node.js that exports the following set of functions:
8+
89
* [jsonStringify()](#jsonstringifyvalue-safe)
910
* [stableJsonStringify()](#stablejsonstringifyvalue-comparefunction-safe)
1011

12+
These functions prioritize performance at the expense of certain features. The serialized JSON output of these functions is identical to that of `JSON.stringify()` with the following exceptions:
13+
14+
1. When serializing strings, only quotation marks (`"`) and backslashes (`\`) are escaped. As the vast majority of strings in real world usage do not include ASCII control characters or lone surrogate code points, a significant performance boost is gained by not checking for their presence. If you require this functionality, it is best to stick with `JSON.stringify()` or another alternative.
15+
2. `toJSON()` methods are completely ignored. However, `Buffer` and `Date` objects *will* be transformed to represent the same output you would get from `JSON.stringify()`.
16+
17+
These functions also do not have *replacer* or *space* parameters like `JSON.stringify()` does.
18+
19+
**Note:**
20+
By default, a check will be made on all nested objects and arrays for circular references, and an `Error` will be thrown if one is encountered. Setting the *safe* parameter to `false` will disable this check and grant a considerable speed boost. If a circular reference is found when *safe* is set to `false`, the internal serialization function will be called recursively until the call stack size is exceeded.
21+
1122
## Installation
1223

1324
```bash
1425
npm i @tuft/json-stringify
1526
```
1627

17-
</br>
18-
<p align="center">
19-
🔹 🔹 🔹
20-
</p>
21-
</br>
28+
## API
2229

2330
### jsonStringify(*value*[, *safe*])
2431

25-
A more performant version of `JSON.stringify()`. Strings produced by this function are identical (not accounting for the order of keys) to the output of `JSON.stringify()`, and it works the same with the following exceptions:
26-
* There are no *replacer* or *space* parameters.
27-
* There **is** a *safe* parameter (see below).
28-
* `toJSON()` methods are completely ignored. However, `Buffer` and `Date` objects will be transformed to represent the same output you would get from `JSON.stringify()`.
32+
Converts a JavaScript object or value to a JSON string. The following are valid data types that can be converted to JSON:
33+
34+
* `null`
35+
* Boolean
36+
* Number
37+
* String
38+
* Array
39+
* Object
40+
* `Date`**
41+
* `Buffer`**
2942

30-
**Important note:**
31-
By default a check will be made on all nested objects and arrays for circular references, and an `Error` will be thrown if one is encountered. Setting the *safe* parameter to `false` will disable this check and grant a considerable speed boost, but this should not be done unless it is certain the given object contains no circular references.
43+
\*\* `Date` and `Buffer` objects are serialized in a way that matches the output of their respective `toJSON()` methods.
3244

3345
#### Parameters
3446

@@ -58,15 +70,9 @@ const obj = {
5870
jsonStringify(obj); // '{"foo":42,"hello":"world"}'
5971
```
6072

61-
</br>
62-
<p align="center">
63-
🔹 🔹 🔹
64-
</p>
65-
</br>
66-
6773
### stableJsonStringify(*value*,[ *compareFunction*[, *safe*]])
6874

69-
A deterministic version of `jsonStringify()`. It performs the same as `jsonStringify()` with the exception that object entries are sorted before being serialized. This ensures that consistent output is produced for the same input, at the cost of reduced performance.
75+
A deterministic version of `jsonStringify()`. It performs the same, with the exception that object entries are sorted before being serialized. This ensures that consistent output is produced for the same input, at the cost of reduced performance.
7076

7177
#### Parameters
7278

@@ -126,8 +132,3 @@ const obj = {
126132

127133
stableJsonStringify(obj); // '{"c":"bar","b":"foo","a":"baz"}'
128134
```
129-
130-
</br>
131-
<p align="center">
132-
🔹 🔹 🔹
133-
</p>

0 commit comments

Comments
 (0)