Skip to content

Commit d4597ea

Browse files
Merge pull request #13 from sandstreamdev/enable_typescript
Enable TypeScript
2 parents cee0863 + 616aa1d commit d4597ea

File tree

254 files changed

+3673
-66
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

254 files changed

+3673
-66
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
index.cjs.js
2+
index.umd.js

.eslintrc.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
module.exports = {
2+
env: {
3+
es6: true
4+
},
5+
extends: ["eslint:recommended"],
6+
parser: "@typescript-eslint/parser",
7+
parserOptions: {
8+
ecmaVersion: 2018,
9+
sourceType: "module"
10+
},
11+
plugins: ["@typescript-eslint", "import"],
12+
rules: {
13+
"arrow-parens": ["error", "as-needed"],
14+
"no-sparse-arrays": 0,
15+
"padding-line-between-statements": [
16+
"error",
17+
{ blankLine: "always", prev: "*", next: "export" },
18+
{
19+
blankLine: "always",
20+
prev: ["const", "let", "var"],
21+
next: "block-like"
22+
},
23+
{
24+
blankLine: "always",
25+
next: ["const", "let", "var", "multiline-expression", "expression"],
26+
prev: "import"
27+
},
28+
{ blankLine: "always", prev: "block-like", next: "*" },
29+
{ blankLine: "always", prev: "import", next: "export" },
30+
{
31+
blankLine: "always",
32+
prev: "export",
33+
next: ["const", "let", "var", "multiline-expression", "expression"]
34+
},
35+
{
36+
blankLine: "always",
37+
next: ["multiline-const", "multiline-let", "multiline-var"],
38+
prev: "*"
39+
},
40+
{
41+
blankLine: "always",
42+
prev: "*",
43+
next: "return"
44+
},
45+
{
46+
blankLine: "always",
47+
prev: ["multiline-const", "multiline-let", "multiline-var"],
48+
next: "*"
49+
}
50+
]
51+
}
52+
};

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ typings/
6262

6363
index.cjs.js
6464
index.umd.js
65+
**/*.d.ts

addExtensions.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* eslint-env node */
2+
// eslint-disable console
3+
import { promises } from "fs";
4+
import path from "path";
5+
import os from "os";
6+
import pQueue from "p-queue";
7+
8+
const CONCURRENCY = Math.max(1, os.cpus().length - 1);
9+
10+
const { default: PQueue } = pQueue;
11+
12+
import ignored from "./ignore.js";
13+
14+
const [sourceIgnoredFiles, ignoredDirectories] = ignored;
15+
16+
const ignoredFiles = sourceIgnoredFiles.filter(x => x !== "index.js");
17+
18+
const {
19+
readdir: readDirectoryAsync,
20+
readFile: readFileAsync,
21+
writeFile: writeFileAsync
22+
} = promises;
23+
24+
const [, , cwd = process.cwd()] = process.argv;
25+
const root = cwd;
26+
27+
const extension = /\.js$/i;
28+
29+
const main = async cwd => {
30+
console.log(`Fixing files in ${cwd}...`);
31+
32+
const entries = await readDirectoryAsync(cwd, { withFileTypes: true });
33+
34+
const files = entries
35+
.filter(x => x.isFile())
36+
.map(x => x.name)
37+
.filter(x => extension.test(x))
38+
.filter(x => !ignoredFiles.includes(x));
39+
40+
const directories = entries
41+
.filter(x => x.isDirectory())
42+
.map(x => x.name)
43+
.filter(x => !ignoredDirectories.includes(x));
44+
45+
for (const directory of directories) {
46+
await main(path.join(cwd, directory));
47+
}
48+
49+
const processFile = async file => {
50+
const filePath = path.join(cwd, file);
51+
const relativeFilePath = path.relative(root, filePath);
52+
53+
try {
54+
console.log(`Fixing ${relativeFilePath}...`);
55+
56+
const contents = await readFileAsync(filePath, "utf-8");
57+
58+
const withExtensions = contents
59+
.replace(/from ["'](.*?)\/["']/gm, 'from "$1/index"')
60+
.replace(/from ["'](.*?)["']/gm, 'from "$1.js"')
61+
.replace(/(\.js)+/g, ".js");
62+
63+
await writeFileAsync(filePath, withExtensions);
64+
65+
console.log(`Fixed ${relativeFilePath}`);
66+
} catch (error) {
67+
console.error(error);
68+
69+
process.exit(1);
70+
}
71+
};
72+
73+
const queue = new PQueue({ concurrency: CONCURRENCY });
74+
75+
for (const file of files) {
76+
queue.add(() => processFile(file));
77+
}
78+
79+
await queue.onIdle();
80+
};
81+
82+
main(cwd);

array/any.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default xs => xs && xs.length > 0;

array/are.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import is from "./is";
2+
3+
export default (...xs) => xs.every(is);

array/difference.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default (xs, ys) => {
2+
const zs = new Set(ys);
3+
4+
return xs.filter(x => !zs.has(x));
5+
};

array/differs.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default (xs, ys) =>
2+
(!xs && ys) ||
3+
(!ys && xs) ||
4+
xs.length !== ys.length ||
5+
xs.some((x, index) => x !== ys[index]);

array/duplicates.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export default xs =>
2+
xs.filter((value, index, self) => self.indexOf(value) !== index);

array/empty.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default [];

0 commit comments

Comments
 (0)