Skip to content

Commit 9d41c45

Browse files
committed
remove es6 polyfill and add native ts implementation for node 4.x. also issue from close #2
1 parent 5ef9906 commit 9d41c45

File tree

8 files changed

+85
-71
lines changed

8 files changed

+85
-71
lines changed

.gitignore

+1-9
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,4 @@
22
.idea/
33
npm-debug.log
44
node_modules/
5-
bin/*.js
6-
bin/*.js.map
7-
src/*.d.ts
8-
src/*.js
9-
src/*.js.map
10-
src/*.d.ts
11-
src/**/*.js
12-
src/**/*.js.map
13-
src/**/*.d.ts
5+
release/

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
22
"name": "typescript-standard",
3-
"version": "0.2.15",
3+
"version": "0.2.17",
44
"description": "Zero-configuration TypeScript Standard Validation",
5-
"main": "./bin/index.js",
5+
"main": "./release/lib/index.js",
66
"bin": {
7-
"standard": "./bin/cli.js"
7+
"standard": "./release/bin/cli.js"
88
},
99
"scripts": {
10-
"build": "npm run build:clean && npm run build:webpack",
10+
"build": "npm run build:clean && npm run build:tsc",
1111
"build:clean": "rm -f ./bin/*.js",
12+
"build:tsc": "node_modules/.bin/tsc -p tsconfig.release.json",
1213
"build:webpack": "node_modules/.bin/webpack --display-error-details --config ./webpack.config.ts",
1314
"prepublish": "npm run build"
1415
},
1516
"files": [
16-
"bin/cli.js",
17-
"bin/index.js",
17+
"release",
1818
"LICENSE",
1919
"README.md",
2020
"tslint.json"

src/bin/cli.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import {lint} from '../lib'
2-
import {ValidatorOutputFormat} from '../lib/validator/format'
1+
import { lint } from '../lib'
2+
import { ValidatorOutputFormat } from '../lib/validator/format'
33
import * as process from 'process'
4-
import {expend} from '../lib/utils'
5-
import {ValidatorCallback} from '../lib/option'
6-
import {ValidateResult} from '../lib/validator/result'
4+
import { expend, includesInArray, startsWith } from '../lib/utils'
5+
import { ValidatorCallback } from '../lib/option'
6+
import { ValidateResult } from '../lib/validator/result'
77

88
// const intercepter = process.argv[0];
99
// const entry = process.argv[1];
1010
const parameters = process.argv.slice(2);
11-
const otherParameters = parameters.filter(p => !p.startsWith('-'));
12-
const isPrettyFlag = parameters.includes('--pretty');
13-
const isVerboseFlag = parameters.includes('--verbose');
11+
const otherParameters = parameters.filter(p => !startsWith(p, '-'));
12+
const isPrettyFlag = includesInArray(parameters, '--pretty');
13+
const isVerboseFlag = includesInArray(parameters, '--verbose');
1414

1515
let files = null;
1616

src/lib/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import '../lib/utils/polyfill'
21
import {ValidatorConfigParser, Validator} from '../lib/validator'
32
import {IOptions} from './option'
43
import {ValidatorOutputFormat} from './validator/format'

src/lib/utils/index.ts

+32
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,35 @@ export function expend(files: Array<string>): Array<string> {
5353
}
5454
return expended;
5555
}
56+
57+
export function includesInArray(arrayList, searchElement): boolean {
58+
59+
var O = Object(arrayList);
60+
var len = parseInt(O.length, 10) || 0;
61+
if (len === 0) {
62+
return false;
63+
}
64+
var n = parseInt(arguments[1], 10) || 0;
65+
var k;
66+
if (n >= 0) {
67+
k = n;
68+
} else {
69+
k = len + n;
70+
if (k < 0) {k = 0;}
71+
}
72+
var currentElement;
73+
while (k < len) {
74+
currentElement = O[k];
75+
if (searchElement === currentElement ||
76+
(searchElement !== searchElement && currentElement !== currentElement)) { // NaN !== NaN
77+
return true;
78+
}
79+
k++;
80+
}
81+
return false;
82+
83+
}
84+
85+
export function startsWith(source: string, searchElement: string): boolean {
86+
return source.indexOf(searchElement) === 0;
87+
}

src/lib/utils/polyfill.ts

-32
This file was deleted.

src/lib/validator/config.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as path from 'path'
22
import * as glob from 'glob'
3-
import {findup, find, load, isDirectory} from '../utils'
4-
import {ValidatorOption} from './option'
5-
import {ValidatorOutputFormat} from './format'
3+
import { findup, find, load, isDirectory, includesInArray, startsWith } from '../utils'
4+
import { ValidatorOption } from './option'
5+
import { ValidatorOutputFormat } from './format'
66

77
export class ValidatorConfigParser {
8-
8+
99
options(format: ValidatorOutputFormat): ValidatorOption {
1010
const defaultTSLintOptions = findup('tslint.json');
1111
if (!defaultTSLintOptions) {
@@ -14,28 +14,28 @@ export class ValidatorConfigParser {
1414
const configuration = load(defaultTSLintOptions);
1515
return new ValidatorOption(format, configuration);
1616
}
17-
17+
1818
files(): Array<string> {
19-
19+
2020
const userTSConfig = find('tsconfig.json');
2121
if (!userTSConfig) {
2222
return [];
2323
}
24-
24+
2525
const config = load(userTSConfig);
2626
const rootDir = path.dirname(userTSConfig);
2727
let includes: Array<string> = [];
2828
let excludes: Array<string> = [];
2929
let excludeFiles: Array<string> = [];
3030
let excludeFolders: Array<string> = [];
31-
31+
3232
// https://www.typescriptlang.org/docs/handbook/tsconfig-json.html
3333
if (config.files && config.files.forEach) {
3434
config.files.forEach(function (file) {
3535
includes.push(path.join(rootDir, file));
3636
})
3737
}
38-
38+
3939
// Added in typescript 2
4040
if (config.include && config.include.forEach) {
4141
config.include.forEach(function (file) {
@@ -47,7 +47,7 @@ export class ValidatorConfigParser {
4747
}
4848
})
4949
}
50-
50+
5151
// Added in typescript 2.0
5252
if (config.exclude && config.exclude.forEach) {
5353
config.exclude.forEach(function (file) {
@@ -70,28 +70,28 @@ export class ValidatorConfigParser {
7070
}
7171
else {
7272
const matches = excludeFolders.filter(function (folder) {
73-
return exclude.startsWith(folder);
73+
return startsWith(exclude, folder);
7474
});
7575
// does any exclude rule match the file?
7676
return !matches.length;
7777
}
7878
});
7979
}
8080
}
81-
81+
8282
// filter results
8383
return includes.filter(function (file) {
8484
// filter file
85-
if (excludeFiles.includes(file)) {
85+
if (includesInArray(excludeFiles, file)) {
8686
return false;
8787
}
8888
// filter by folders
8989
const matches = excludeFolders.filter(function (exclude) {
90-
return file.startsWith(exclude);
90+
return startsWith(file, exclude);
9191
});
9292
// does any exclude rule match the file?
9393
return !matches.length;
9494
});
9595
}
96-
96+
9797
}

tsconfig.release.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": [
5+
"es5"
6+
],
7+
"declaration": true,
8+
"module": "commonjs",
9+
"newLine": "LF",
10+
"removeComments": true,
11+
"experimentalDecorators": true,
12+
"sourceMap": true,
13+
"outDir": "release",
14+
"pretty": true
15+
},
16+
"include": [
17+
"src/**/*.ts"
18+
],
19+
"exclude": [
20+
"node_modules",
21+
"src/**/*.spec.ts"
22+
]
23+
}

0 commit comments

Comments
 (0)