Skip to content

Commit 8be7d57

Browse files
committed
Use ts-scripts for development
1 parent 13efc6e commit 8be7d57

File tree

12 files changed

+13382
-4065
lines changed

12 files changed

+13382
-4065
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ stringify({ uno: 1, dos: 2 }, null, "\t"); // "{\n\tuno: 1,\n\tdos: 2\n}"
7979
* Add custom replacer behaviour - like double quoted strings.
8080
*/
8181

82-
stringify(["test", "string"], function(value, indent, stringify) {
82+
stringify(["test", "string"], function (value, indent, stringify) {
8383
if (typeof value === "string") {
8484
return '"' + value.replace(/"/g, '\\"') + '"';
8585
}
@@ -99,10 +99,15 @@ const { stringify } = require("javascript-stringify");
9999

100100
const { APP_ROOT_PATH, ESLINTRC_FILE_PATH } = require("./constants");
101101

102-
const ESLINT_CLI = new CLIEngine({ fix: true, cwd: APP_ROOT_PATH, configFile: ESLINTRC_FILE_PATH });
102+
const ESLINT_CLI = new CLIEngine({
103+
fix: true,
104+
cwd: APP_ROOT_PATH,
105+
configFile: ESLINTRC_FILE_PATH,
106+
});
103107

104108
module.exports = (objectToStringify) => {
105-
return ESLINT_CLI.executeOnText(stringify(objectToStringify)).results[0].output;
109+
return ESLINT_CLI.executeOnText(stringify(objectToStringify)).results[0]
110+
.output;
106111
};
107112
```
108113

package-lock.json

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

package.json

Lines changed: 25 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
{
22
"name": "javascript-stringify",
33
"version": "2.0.1",
4+
"publishConfig": {
5+
"access": "public"
6+
},
47
"description": "Stringify is to `eval` as `JSON.stringify` is to `JSON.parse`",
8+
"license": "MIT",
9+
"repository": "https://github.com/blakeembrey/javascript-stringify.git",
10+
"author": {
11+
"name": "Blake Embrey",
12+
"email": "hello@blakeembrey.com",
13+
"url": "http://blakeembrey.me"
14+
},
15+
"homepage": "https://github.com/blakeembrey/javascript-stringify",
16+
"bugs": {
17+
"url": "https://github.com/blakeembrey/javascript-stringify/issues"
18+
},
519
"main": "dist/index.js",
6-
"types": "dist/index.d.ts",
20+
"scripts": {
21+
"format": "ts-scripts format",
22+
"lint": "ts-scripts lint",
23+
"prepare": "ts-scripts install && ts-scripts build",
24+
"specs": "ts-scripts specs",
25+
"test": "ts-scripts test"
26+
},
727
"files": [
828
"dist/"
929
],
10-
"scripts": {
11-
"prettier": "prettier --write",
12-
"format": "npm run prettier -- \"{.,src/**}/*.{js,ts,json,md,yml,css}\"",
13-
"lint": "tslint \"src/**/*.ts\" --project tsconfig.json",
14-
"build": "rimraf dist/ && tsc",
15-
"specs": "jest --coverage",
16-
"test": "npm run lint && npm run build && npm run specs",
17-
"prepare": "npm run build"
18-
},
19-
"repository": "https://github.com/blakeembrey/javascript-stringify.git",
2030
"keywords": [
2131
"stringify",
2232
"javascript",
@@ -25,53 +35,14 @@
2535
"string",
2636
"code"
2737
],
28-
"author": {
29-
"name": "Blake Embrey",
30-
"email": "hello@blakeembrey.com",
31-
"url": "http://blakeembrey.me"
32-
},
33-
"license": "MIT",
34-
"bugs": {
35-
"url": "https://github.com/blakeembrey/javascript-stringify/issues"
36-
},
37-
"homepage": "https://github.com/blakeembrey/javascript-stringify",
38-
"jest": {
39-
"roots": [
40-
"<rootDir>/src/"
41-
],
42-
"transform": {
43-
"\\.tsx?$": "ts-jest"
44-
}
45-
},
46-
"husky": {
47-
"hooks": {
48-
"pre-commit": "lint-staged"
49-
}
50-
},
51-
"lint-staged": {
52-
"*.{js,ts,json,md,yml,css}": [
53-
"npm run prettier",
54-
"git add"
55-
]
56-
},
57-
"publishConfig": {
58-
"access": "public"
59-
},
6038
"devDependencies": {
39+
"@borderless/ts-scripts": "^0.4.1",
6140
"@types/jest": "^24.0.9",
6241
"@types/node": "^11.10.4",
6342
"@types/semver": "^5.5.0",
6443
"fast-check": "^1.12.0",
65-
"husky": "^1.3.1",
66-
"jest": "^24.0.0",
67-
"lint-staged": "^8.1.1",
68-
"prettier": "^1.16.1",
69-
"rimraf": "^2.5.4",
7044
"semver": "^5.6.0",
71-
"ts-jest": "^24.0.0",
72-
"tslint": "^5.0.0",
73-
"tslint-config-prettier": "^1.17.0",
74-
"tslint-config-standard": "^8.0.0",
75-
"typescript": "^3.3.1"
76-
}
45+
"typescript": "^4.2.4"
46+
},
47+
"types": "dist/index.d.ts"
7748
}

src/array.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ToString } from "./types";
66
export const arrayToString: ToString = (array: any[], space, next) => {
77
// Map array values to their stringified values with correct indentation.
88
const values = array
9-
.map(function(value, index) {
9+
.map(function (value, index) {
1010
const result = next(value, index);
1111

1212
if (result === undefined) return String(result);

src/function.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const METHOD_NAMES_ARE_QUOTED =
99
{
1010
" "() {
1111
/* Empty. */
12-
}
12+
},
1313
}[" "]
1414
.toString()
1515
.charAt(0) === '"';
@@ -18,14 +18,14 @@ const FUNCTION_PREFIXES = {
1818
Function: "function ",
1919
GeneratorFunction: "function* ",
2020
AsyncFunction: "async function ",
21-
AsyncGeneratorFunction: "async function* "
21+
AsyncGeneratorFunction: "async function* ",
2222
};
2323

2424
const METHOD_PREFIXES = {
2525
Function: "",
2626
GeneratorFunction: "*",
2727
AsyncFunction: "async ",
28-
AsyncGeneratorFunction: "async *"
28+
AsyncGeneratorFunction: "async *",
2929
};
3030

3131
const TOKENS_PRECEDING_REGEXPS = new Set(
@@ -38,7 +38,7 @@ const TOKENS_PRECEDING_REGEXPS = new Set(
3838
/**
3939
* Track function parser usage.
4040
*/
41-
export const USED_METHOD_KEY = new WeakSet<Function>();
41+
export const USED_METHOD_KEY = new WeakSet<(...args: unknown[]) => unknown>();
4242

4343
/**
4444
* Stringify a function.
@@ -85,7 +85,7 @@ export class FunctionParser {
8585
hadKeyword = false;
8686

8787
constructor(
88-
public fn: Function,
88+
public fn: (...args: unknown[]) => unknown,
8989
public indent: string,
9090
public next: Next,
9191
public key?: string
@@ -147,14 +147,12 @@ export class FunctionParser {
147147
if (this.isMethodCandidate && !this.hadKeyword) {
148148
offset = this.pos;
149149
}
150-
// tslint:disable-next-line no-switch-case-fall-through
151150
case "()":
152151
if (this.fnString.substr(this.pos, 2) === "=>") {
153152
return this.keyPrefix + this.fnString;
154153
}
155154

156155
this.pos = offset;
157-
// tslint:disable-next-line no-switch-case-fall-through
158156
case '"':
159157
case "'":
160158
case "[]":
@@ -203,10 +201,8 @@ export class FunctionParser {
203201
* Attempt to advance the parser past the keywords expected to be at the
204202
* start of this function's definition. This method sets `this.hadKeyword`
205203
* based on whether or not a `function` keyword is consumed.
206-
*
207-
* @return {boolean}
208204
*/
209-
tryParsePrefixTokens() {
205+
tryParsePrefixTokens(): boolean {
210206
let posPrev = this.pos;
211207

212208
this.hadKeyword = false;
@@ -216,7 +212,6 @@ export class FunctionParser {
216212
if (this.consumeSyntax() !== "async") return false;
217213

218214
posPrev = this.pos;
219-
// tslint:disable-next-line no-switch-case-fall-through
220215
case "Function":
221216
if (this.consumeSyntax() === "function") {
222217
this.hadKeyword = true;
@@ -226,7 +221,6 @@ export class FunctionParser {
226221
return true;
227222
case "AsyncGeneratorFunction":
228223
if (this.consumeSyntax() !== "async") return false;
229-
// tslint:disable-next-line no-switch-case-fall-through
230224
case "GeneratorFunction":
231225
let token = this.consumeSyntax();
232226

@@ -248,9 +242,9 @@ export class FunctionParser {
248242
*
249243
* (This isn't a full parser, so the token scanning logic used here is as
250244
* simple as it can be. As a consequence, some things that are one token in
251-
* JavaScript, like decimal number literals or most multicharacter operators
245+
* JavaScript, like decimal number literals or most multi-character operators
252246
* like '&&', are split into more than one token here. However, awareness of
253-
* some multicharacter sequences like '=>' is necessary, so we match the few
247+
* some multi-character sequences like '=>' is necessary, so we match the few
254248
* of them that we care about.)
255249
*/
256250
consumeSyntax(wordLikeToken?: string) {

0 commit comments

Comments
 (0)