Skip to content

Commit e209e06

Browse files
committed
Slightly optimized createBoundary helper and separated config for .d.ts output.
1 parent dc9adec commit e209e06

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

lib/util/createBoundary.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ function createBoundary(size: number): string {
1010
let res = ""
1111

1212
while (size--) {
13-
res += alphabet[Math.floor(Math.random() * alphabet.length)]
13+
// I use bitwise `<<` here for slightly more performant string fill.
14+
// It will basically do same thing as `Math.truc()`,
15+
// except it only support signed 32-bit integers.
16+
// Because the result of this operation will always be
17+
// a number in range `0` and `alphabet.length - 1` (inclusive),
18+
// so we don't need `Math.floor()` too.
19+
/* eslint no-bitwise: ["error", {"allow": ["<<"]}] */
20+
res += alphabet[(Math.random() * alphabet.length) << 0]
1421
}
1522

1623
return res

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"ci": "c8 npm test && c8 report --reporter=json",
2828
"build:esm": "ttsc --project tsconfig.esm.json",
2929
"build:cjs": "ttsc --project tsconfig.cjs.json",
30-
"build": "npm run build:esm && npm run build:cjs",
30+
"build:types": "ttsc --project tsconfig.d.ts.json",
31+
"build": "npm run build:esm && npm run build:cjs && npm run build:types",
3132
"test": "ava --fail-fast",
3233
"cleanup": "npx rimraf @type \"lib/**/*.js\"",
3334
"prepare": "npm run cleanup && npm run build",

tsconfig.d.ts.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.esm.json",
3+
"compilerOptions": {
4+
"declaration": true,
5+
"declarationDir": "./@type",
6+
"removeComments": false,
7+
"emitDeclarationOnly": true
8+
}
9+
}

tsconfig.esm.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
44
"module": "es2020",
5-
"outDir": "lib/esm",
6-
"declaration": true,
7-
"declarationDir": "./@type",
5+
"outDir": "lib/esm"
86
}
97
}

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
"forceConsistentCasingInFileNames": true,
2222
"allowSyntheticDefaultImports": true,
2323
"experimentalDecorators": true,
24+
"removeComments": true,
2425
"plugins": [
2526
{
2627
"transform": "@zoltu/typescript-transformer-append-js-extension/output/index.js",
2728
"after": true
2829
}
2930
]
3031
}
31-
}
32+
}

0 commit comments

Comments
 (0)