Skip to content

Commit bb3be27

Browse files
authored
Merge pull request #1 from sxwei123/develop
Setup Github Actions for unit test
2 parents aab1c68 + 40c449f commit bb3be27

25 files changed

+5225
-325
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

.eslintrc.yml

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1-
extends: eslint:recommended
2-
env:
3-
node: true
4-
browser: true
1+
---
2+
parser: "@typescript-eslint/parser"
3+
plugins:
4+
- "@typescript-eslint"
5+
extends:
6+
- "plugin:@typescript-eslint/recommended"
7+
- eslint-config-prettier
8+
- plugin:import/errors
9+
- plugin:import/warnings
10+
- plugin:import/typescript
511
rules:
6-
block-scoped-var: 2
7-
callback-return: 2
8-
dot-notation: 2
9-
indent: 2
10-
linebreak-style: [2, unix]
11-
new-cap: 2
12-
no-console: [2, allow: [warn, error]]
13-
no-else-return: 2
14-
no-eq-null: 2
15-
no-fallthrough: 2
16-
no-invalid-this: 2
17-
no-return-assign: 2
18-
no-shadow: 1
19-
no-trailing-spaces: 2
20-
no-use-before-define: [2, nofunc]
21-
quotes: [2, single, avoid-escape]
22-
semi: [2, always]
23-
strict: [2, global]
24-
valid-jsdoc: [2, requireReturn: false]
25-
no-control-regex: 0
26-
no-useless-escape: 2
12+
"@typescript-eslint/no-unused-vars":
13+
- warn
14+
- argsIgnorePattern: "^_"
15+
no-use-before-define:
16+
- warn
17+
"@typescript-eslint/no-use-before-define":
18+
- warn
19+
no-unused-expressions:
20+
- error
21+
no-underscore-dangle:
22+
- error
23+
- # allow couchdb stuff
24+
allow:
25+
- _id
26+
- _rev
27+
- _deleted
28+
- __typename
29+
allowAfterThis: true
30+
allowAfterSuper: true
31+
enforceInMethodNames: true
32+
one-var:
33+
- error
34+
- never
35+
class-methods-use-this:
36+
- error

.github/workflows/publish.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: "Publish"
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
release:
10+
name: Build and publish
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
- name: Setup node.js
16+
uses: actions/setup-node@v1
17+
with:
18+
node-version: "10.x"
19+
registry-url: "https://registry.npmjs.org"
20+
- run: yarn install
21+
- run: yarn publish
22+
env:
23+
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}

.github/workflows/test.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: "Test"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
jobs:
9+
release:
10+
name: Build and run test
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node-version: [10.x, 12.x, 14.x]
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
- name: Setup node.js ${{ matrix.node-version }}
19+
uses: actions/setup-node@v1
20+
with:
21+
node-version: ${{ matrix.node-version }}
22+
registry-url: "https://registry.npmjs.org"
23+
- run: yarn install
24+
- run: yarn test
25+
env:
26+
NODE_ENV: test

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
node_modules
2-
.nyc_output/
32
coverage/
43
.DS_Store
4+
5+
.vscode
6+
7+
lib

README.md

Lines changed: 32 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,55 @@
1-
# fast-json-stable-stringify
1+
# quick-stable-stringify
22

3-
Deterministic `JSON.stringify()` - a faster version of [@substack](https://github.com/substack)'s json-stable-strigify without [jsonify](https://github.com/substack/jsonify).
3+
Deterministic `JSON.stringify()` - a faster version of [@epoberezkin](https://github.com/epoberezkin)'s [fast-json-stable-strigify](https://github.com/epoberezkin/fast-json-stable-stringify). Built with Typescript and modern Javascript.
44

5-
You can also pass in a custom comparison function.
5+
## Install
66

7-
[![Build Status](https://travis-ci.org/epoberezkin/fast-json-stable-stringify.svg?branch=master)](https://travis-ci.org/epoberezkin/fast-json-stable-stringify)
8-
[![Coverage Status](https://coveralls.io/repos/github/epoberezkin/fast-json-stable-stringify/badge.svg?branch=master)](https://coveralls.io/github/epoberezkin/fast-json-stable-stringify?branch=master)
7+
With npm do:
98

10-
# example
11-
12-
``` js
13-
var stringify = require('fast-json-stable-stringify');
14-
var obj = { c: 8, b: [{z:6,y:5,x:4},7], a: 3 };
15-
console.log(stringify(obj));
9+
```
10+
npm install quick-stable-stringify
1611
```
1712

18-
output:
13+
Or install with yarn:
1914

2015
```
21-
{"a":3,"b":[{"x":4,"y":5,"z":6},7],"c":8}
16+
yarn add quick-stable-stringify
2217
```
2318

19+
## Examples
2420

25-
# methods
26-
27-
``` js
28-
var stringify = require('fast-json-stable-stringify')
21+
```js
22+
var stringify = require("quick-stable-stringify");
23+
var obj = { c: 8, b: [{ z: 6, y: 5, x: 4 }, 7], a: 3 };
24+
console.log(stringify(obj));
2925
```
3026

31-
## var str = stringify(obj, opts)
32-
33-
Return a deterministic stringified string `str` from the object `obj`.
27+
output:
3428

29+
```
30+
{"a":3,"b":[{"x":4,"y":5,"z":6},7],"c":8}
31+
```
3532

36-
## options
33+
## Options
3734

3835
### cmp
3936

4037
If `opts` is given, you can supply an `opts.cmp` to have a custom comparison
4138
function for object keys. Your function `opts.cmp` is called with these
4239
parameters:
4340

44-
``` js
45-
opts.cmp({ key: akey, value: avalue }, { key: bkey, value: bvalue })
41+
```js
42+
opts.cmp({ key: akey, value: avalue }, { key: bkey, value: bvalue });
4643
```
4744

4845
For example, to sort on the object key names in reverse order you could write:
4946

50-
``` js
51-
var stringify = require('fast-json-stable-stringify');
47+
```js
48+
var stringify = require("quick-stable-stringify");
5249

53-
var obj = { c: 8, b: [{z:6,y:5,x:4},7], a: 3 };
50+
var obj = { c: 8, b: [{ z: 6, y: 5, x: 4 }, 7], a: 3 };
5451
var s = stringify(obj, function (a, b) {
55-
return a.key < b.key ? 1 : -1;
52+
return a.key < b.key ? 1 : -1;
5653
});
5754
console.log(s);
5855
```
@@ -87,45 +84,25 @@ Pass `true` in `opts.cycles` to stringify circular property as `__cycle__` - the
8784

8885
TypeError will be thrown in case of circular object without this option.
8986

90-
91-
# install
92-
93-
With [npm](https://npmjs.org) do:
94-
95-
```
96-
npm install fast-json-stable-stringify
97-
```
98-
99-
10087
# benchmark
10188

10289
To run benchmark (requires Node.js 6+):
90+
10391
```
10492
node benchmark
10593
```
10694

10795
Results:
96+
10897
```
109-
fast-json-stable-stringify x 17,189 ops/sec ±1.43% (83 runs sampled)
110-
json-stable-stringify x 13,634 ops/sec ±1.39% (85 runs sampled)
111-
fast-stable-stringify x 20,212 ops/sec ±1.20% (84 runs sampled)
112-
faster-stable-stringify x 15,549 ops/sec ±1.12% (84 runs sampled)
113-
The fastest is fast-stable-stringify
98+
quick-stable-stringify x 25,499 ops/sec ±1.79% (82 runs sampled)
99+
fast-json-stable-stringify x 18,566 ops/sec ±0.43% (89 runs sampled)
100+
json-stable-stringify x 14,453 ops/sec ±0.62% (88 runs sampled)
101+
fast-stable-stringify x 20,763 ops/sec ±0.58% (88 runs sampled)
102+
faster-stable-stringify x 18,320 ops/sec ±0.90% (88 runs sampled)
103+
The fastest is quick-stable-stringify
114104
```
115105

116-
117-
## Enterprise support
118-
119-
fast-json-stable-stringify package is a part of [Tidelift enterprise subscription](https://tidelift.com/subscription/pkg/npm-fast-json-stable-stringify?utm_source=npm-fast-json-stable-stringify&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) - it provides a centralised commercial support to open-source software users, in addition to the support provided by software maintainers.
120-
121-
122-
## Security contact
123-
124-
To report a security vulnerability, please use the
125-
[Tidelift security contact](https://tidelift.com/security).
126-
Tidelift will coordinate the fix and disclosure. Please do NOT report security vulnerability via GitHub issues.
127-
128-
129106
# license
130107

131108
[MIT](https://github.com/epoberezkin/fast-json-stable-stringify/blob/master/LICENSE)

benchmark/index.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
1-
'use strict';
2-
3-
const Benchmark = require('benchmark');
4-
const suite = new Benchmark.Suite;
5-
const testData = require('./test.json');
1+
"use strict";
62

3+
const Benchmark = require("benchmark");
4+
const suite = new Benchmark.Suite();
5+
const testData = require("./test.json");
76

87
const stringifyPackages = {
9-
// 'JSON.stringify': JSON.stringify,
10-
'fast-json-stable-stringify': require('../index'),
11-
'json-stable-stringify': true,
12-
'fast-stable-stringify': true,
13-
'faster-stable-stringify': true
8+
"quick-stable-stringify": require("../dist/index"),
9+
"fast-json-stable-stringify": true,
10+
"json-stable-stringify": true,
11+
"fast-stable-stringify": true,
12+
"faster-stable-stringify": true,
1413
};
1514

16-
1715
for (const name in stringifyPackages) {
1816
let func = stringifyPackages[name];
1917
if (func === true) func = require(name);
2018

21-
suite.add(name, function() {
19+
suite.add(name, function () {
2220
func(testData);
2321
});
2422
}
2523

2624
suite
27-
.on('cycle', (event) => console.log(String(event.target)))
28-
.on('complete', function () {
29-
console.log('The fastest is ' + this.filter('fastest').map('name'));
25+
.on("cycle", (event) => console.log(String(event.target)))
26+
.on("complete", function () {
27+
console.log("The fastest is " + this.filter("fastest").map("name"));
3028
})
31-
.run({async: true});
29+
.run({ async: true });

dist/index.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
interface KeyValue {
2+
key: string;
3+
value: any;
4+
}
5+
declare type ComparatorFunction = (a: KeyValue, b: KeyValue) => number;
6+
interface Option {
7+
cmp?: ComparatorFunction;
8+
cycles?: boolean;
9+
}
10+
declare const jsonStringify: {
11+
(data: any, opts?: Option | ComparatorFunction | undefined): string | undefined;
12+
default: any;
13+
};
14+
export = jsonStringify;

dist/index.js

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)