Skip to content

Commit 643db63

Browse files
committed
feat: typescript migration
1 parent fd583dc commit 643db63

File tree

8 files changed

+1075
-190
lines changed

8 files changed

+1075
-190
lines changed

.babelrc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
2-
"presets": [["latest-node", {"target": "10"}]],
3-
"plugins": [],
4-
"sourceMaps": false
2+
"presets": ["@babel/preset-env", "@babel/typescript"],
3+
"plugins": [
4+
"@babel/proposal-class-properties",
5+
"@babel/proposal-object-rest-spread"
6+
]
57
}

.idea/codeStyles/codeStyleConfig.xml

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

.idea/jsLinters/eslint.xml

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

package.json

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
"main": "lib/index.js",
66
"scripts": {
77
"clean": "rm -rf lib",
8-
"build": "npx babel src --out-dir lib --copy-files --include-dotfiles --config-file ./.babelrc",
8+
"build:js": "npx babel src --out-dir lib --copy-files --include-dotfiles --config-file ./.babelrc --extensions '.ts,.tsx'",
9+
"build:types": "tsc --emitDeclarationOnly",
10+
"build": "npm run build:types && npm run build:js",
911
"build-clean": "yarn run clean && yarn run build",
10-
"test-simple": "nyc mocha \"./test/**/*.spec.js\"",
12+
"test-simple": "nyc mocha \"./test/**/*.spec.{js,ts}\"",
1113
"test": "yarn run clean && yarn run gardener && yarn run test-simple",
1214
"coveralls": "node ./node_modules/coveralls/bin/coveralls.js < ./coverage/lcov.info",
1315
"semantic-release": "yarn run build-clean && npx semantic-release",
@@ -44,24 +46,30 @@
4446
},
4547
"homepage": "https://github.com/blackflux/object-treeify#readme",
4648
"devDependencies": {
47-
"@babel/cli": "7.12.1",
48-
"@babel/core": "7.12.3",
49+
"@babel/cli": "^7.12.1",
50+
"@babel/core": "^7.12.3",
51+
"@babel/preset-env": "^7.12.1",
52+
"@babel/preset-typescript": "^7.12.1",
4953
"@babel/register": "7.12.1",
50-
"@blackflux/eslint-plugin-rules": "1.3.41",
51-
"@blackflux/robo-config-plugin": "3.10.14",
54+
"@blackflux/eslint-plugin-rules": "1.3.40",
55+
"@blackflux/robo-config-plugin": "3.10.9",
56+
"@types/chai": "4.2.14",
57+
"@types/mocha": "8.0.3",
5258
"babel-eslint": "10.1.0",
59+
"babel-preset-latest-node": "5.0.0",
5360
"chai": "4.2.0",
5461
"coveralls": "3.1.0",
55-
"eslint": "7.13.0",
56-
"eslint-config-airbnb-base": "14.2.1",
62+
"eslint": "7.11.0",
63+
"eslint-config-airbnb-base": "14.2.0",
5764
"eslint-plugin-import": "2.22.1",
5865
"eslint-plugin-json": "2.1.2",
5966
"eslint-plugin-markdown": "1.0.2",
6067
"eslint-plugin-mocha": "8.0.0",
61-
"js-gardener": "2.0.179",
68+
"js-gardener": "2.0.177",
6269
"nyc": "15.1.0",
63-
"semantic-release": "17.2.3",
64-
"babel-preset-latest-node": "5.1.1"
70+
"semantic-release": "17.2.1",
71+
"ts-node": "9.0.0",
72+
"typescript": "^4.0.3"
6573
},
6674
"nyc": {
6775
"tempDir": "./coverage/.nyc_output",
@@ -73,18 +81,21 @@
7381
"functions": 100,
7482
"branches": 100,
7583
"include": [
76-
"**/*.js"
84+
"**/*.js",
85+
"**/*.ts"
7786
],
7887
"reporter": [
7988
"lcov",
8089
"text-summary"
8190
],
8291
"require": [
83-
"@babel/register"
92+
"ts-node/register"
93+
],
94+
"extension": [
95+
".js",
96+
".ts"
8497
],
85-
"extension": [],
8698
"cache": true,
87-
"all": true,
8899
"babel": true,
89100
"exclude": [
90101
"gardener.js",

src/index.js renamed to src/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const assert = require('assert');
22

3-
const buildCtx = (opts) => {
3+
const buildCtx = (opts: Object) => {
44
const ctx = {
55
joined: true,
66
spacerNoNeighbour: ' ',
@@ -19,17 +19,19 @@ const buildCtx = (opts) => {
1919
return ctx;
2020
};
2121

22-
module.exports = (tree, opts = {}) => {
22+
export default (tree: Object, opts: Object = {}) => {
2323
const ctx = buildCtx(opts);
2424
const result = [];
2525

26-
const sort = (input) => (ctx.sortFn === null ? input.reverse() : input.sort((a, b) => ctx.sortFn(b, a)));
26+
const sort = (input: Array<string>) => (ctx.sortFn === null
27+
? input.reverse()
28+
: input.sort((a, b) => ctx.sortFn(b, a)));
2729

2830
const neighbours = [];
2931
const keys = sort(Object.keys(tree)).map((k) => [k]);
30-
const lookup = [tree];
32+
const lookup : Array<any> = [tree];
3133
while (keys.length !== 0) {
32-
const key = keys.pop();
34+
const key: Array<string> = keys.pop();
3335
const node = lookup[key.length - 1][key[key.length - 1]];
3436

3537
neighbours[key.length - 1] = keys.length !== 0 && keys[keys.length - 1].length === key.length;

test/index.spec.js renamed to test/index.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import treeify from '../src/index';
2+
13
const expect = require('chai').expect;
2-
const treeify = require('../src/index');
34

45
describe('Testing Treeify', () => {
56
it('Testing Comprehensive Null Example', () => {
@@ -99,7 +100,7 @@ describe('Testing Treeify', () => {
99100
9: null
100101
}
101102
}, {
102-
sortFn: (a, b) => Number(b) - Number(a)
103+
sortFn: (a: string, b: string) => Number(b) - Number(a)
103104
})).to.deep.equal([
104105
'├─ 7',
105106
'│ ├─ 9',

tsconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"lib": [
4+
"esnext"
5+
],
6+
"outDir": "./lib",
7+
"target": "esnext",
8+
"declaration": true,
9+
"allowSyntheticDefaultImports": true,
10+
"module": "CommonJS",
11+
"moduleResolution": "Node"
12+
},
13+
"include": [
14+
"./src/*"
15+
]
16+
}

0 commit comments

Comments
 (0)