Skip to content

Commit 3878959

Browse files
committed
Rewrite project with typescript
1 parent aab1c68 commit 3878959

22 files changed

+5534
-259
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

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ node_modules
22
.nyc_output/
33
coverage/
44
.DS_Store
5+
6+
.vscode
7+
8+
lib

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("../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.

index.d.ts

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

index.js

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

jestconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"transform": {
3+
"^.+\\.(t|j)sx?$": "ts-jest"
4+
},
5+
"testRegex": "(/test/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
6+
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"]
7+
}

0 commit comments

Comments
 (0)