Skip to content

Commit 8f89de0

Browse files
committed
Rewrite project in TypeScript
1 parent 565f5ee commit 8f89de0

18 files changed

+7588
-1881
lines changed

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
root = true
4+
5+
[*]
6+
indent_size = 2
7+
indent_style = space
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.DS_Store
2-
node_modules
3-
coverage
2+
dist/
3+
node_modules/
4+
coverage/
5+
npm-debug.log

README.md

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,69 +9,50 @@
99
1010
## Installation
1111

12-
```javascript
13-
npm install javascript-stringify --save
14-
bower install javascript-stringify --save
15-
```
16-
17-
### Node
18-
19-
```javascript
20-
var javascriptStringify = require('javascript-stringify');
2112
```
22-
23-
### AMD
24-
25-
```javascript
26-
define(function (require, exports, module) {
27-
var javascriptStringify = require('javascript-stringify');
28-
});
29-
```
30-
31-
### `<script>` tag
32-
33-
```html
34-
<script src="javascript-stringify.js"></script>
13+
npm install javascript-stringify --save
3514
```
3615

3716
## Usage
3817

3918
```javascript
40-
javascriptStringify(value[, replacer [, space [, options]]])
19+
import { stringify } from "javascript-stringify";
4120
```
4221

43-
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.
44-
45-
The `options` object allows some additional configuration:
22+
The API is similar `JSON.stringify`:
4623

47-
* **maxDepth** _(number, default: 100)_ The maximum depth of values to stringify
48-
* **maxValues** _(number, default: 100000)_ The maximum number of values to stringify
49-
* **references** _(boolean, default: false)_ Restore circular/repeated references in the object (uses IIFE)
50-
* **skipUndefinedProperties** _(boolean, default: false)_ Omits `undefined` properties instead of restoring as `undefined`
24+
- `value` The value to convert to a string
25+
- `replacer` A function that alters the behavior of the stringification process
26+
- `space` A string or number that's used to insert white space into the output for readability purposes
27+
- `options`
28+
- **maxDepth** _(number, default: 100)_ The maximum depth of values to stringify
29+
- **maxValues** _(number, default: 100000)_ The maximum number of values to stringify
30+
- **references** _(boolean, default: false)_ Restore circular/repeated references in the object (uses IIFE)
31+
- **skipUndefinedProperties** _(boolean, default: false)_ Omits `undefined` properties instead of restoring as `undefined`
5132

5233
### Examples
5334

5435
```javascript
55-
javascriptStringify({}); // "{}"
56-
javascriptStringify(true); // "true"
57-
javascriptStringify('foo'); // "'foo'"
36+
stringify({}); // "{}"
37+
stringify(true); // "true"
38+
stringify("foo"); // "'foo'"
5839

59-
javascriptStringify({ x: 5, y: 6}); // "{x:5,y:6}"
60-
javascriptStringify([1, 2, 3, 'string']); // "[1,2,3,'string']"
40+
stringify({ x: 5, y: 6 }); // "{x:5,y:6}"
41+
stringify([1, 2, 3, "string"]); // "[1,2,3,'string']"
6142

62-
javascriptStringify({ a: { b: { c: 1 } } }, null, null, { maxDepth: 2 }); // "{a:{b:{}}}"
43+
stringify({ a: { b: { c: 1 } } }, null, null, { maxDepth: 2 }); // "{a:{b:{}}}"
6344

6445
/**
6546
* Invalid key names are automatically stringified.
6647
*/
6748

68-
javascriptStringify({ 'some-key': 10 }); // "{'some-key':10}"
49+
stringify({ "some-key": 10 }); // "{'some-key':10}"
6950

7051
/**
7152
* Some object types and values can remain identical.
7253
*/
7354

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

7657
/**
7758
* Unknown or circular references are removed.
@@ -80,22 +61,22 @@ javascriptStringify([/.+/ig, new Number(10), new Date()]); // "[/.+/gi,new Numbe
8061
var obj = { x: 10 };
8162
obj.circular = obj;
8263

83-
javascriptStringify(obj); // "{x:10}"
84-
javascriptStringify(obj, null, null, { references: true }); // "(function(){var x={x:10};x.circular=x;return x;}())"
64+
stringify(obj); // "{x:10}"
65+
stringify(obj, null, null, { references: true }); // "(function(){var x={x:10};x.circular=x;return x;}())"
8566

8667
/**
8768
* Specify indentation - just like `JSON.stringify`.
8869
*/
8970

90-
javascriptStringify({ a: 2 }, null, ' '); // "{\n a: 2\n}"
91-
javascriptStringify({ uno: 1, dos : 2 }, null, '\t'); // "{\n\tuno: 1,\n\tdos: 2\n}"
71+
stringify({ a: 2 }, null, " "); // "{\n a: 2\n}"
72+
stringify({ uno: 1, dos: 2 }, null, "\t"); // "{\n\tuno: 1,\n\tdos: 2\n}"
9273

9374
/**
9475
* Add custom replacer behaviour - like double quoted strings.
9576
*/
9677

97-
javascriptStringify(['test', 'string'], function (value, indent, stringify) {
98-
if (typeof value === 'string') {
78+
stringify(["test", "string"], function(value, indent, stringify) {
79+
if (typeof value === "string") {
9980
return '"' + value.replace(/"/g, '\\"') + '"';
10081
}
10182

javascript-stringify.d.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)