Skip to content

Commit f83a1d8

Browse files
committed
Update library to use typescript
1 parent 21266e8 commit f83a1d8

25 files changed

Lines changed: 6443 additions & 409 deletions

.eslintrc

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

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master, main]
6+
pull_request:
7+
branches: [master, main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node-version: [18, 20]
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Use Node.js ${{ matrix.node-version }}
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: ${{ matrix.node-version }}
22+
cache: npm
23+
24+
- run: npm ci
25+
- run: npm run dist
26+
- run: npm run lint
27+
- run: npm test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
dist

.travis.yml

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

eslint.config.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import eslint from '@eslint/js';
2+
import { defineConfig } from 'eslint/config';
3+
import tseslint from 'typescript-eslint';
4+
5+
export default defineConfig(
6+
eslint.configs.recommended,
7+
tseslint.configs.recommended,
8+
{
9+
languageOptions: {
10+
parserOptions: {
11+
ecmaVersion: 2020,
12+
sourceType: 'module'
13+
},
14+
globals: {
15+
console: 'readonly',
16+
process: 'readonly'
17+
}
18+
},
19+
rules: {
20+
'strict': ['error', 'never'],
21+
'quotes': ['error', 'single', { avoidEscape: true }],
22+
'indent': ['error', 2, { SwitchCase: 1 }],
23+
'eol-last': 'error',
24+
'comma-dangle': ['error', 'always-multiline']
25+
}
26+
}
27+
);
Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
'use strict';
1+
import Parth from './src';
22

3-
var input, result;
4-
var parth = require('./.')();
3+
const parth = new Parth();
54

65
// #set
7-
input = [
6+
const input = [
87
'/',
98
'/page',
109
'/page/:number(\\d+)',
@@ -21,22 +20,23 @@ input = [
2120
'(get|post) /:page(\\w+)/:Number(\\d+)',
2221
'get /page/number',
2322
'(get|post) /:page(\\w+)/:view([^.\\/\\s]+)',
24-
'1', '2', '1 2',
23+
'1',
24+
'2',
25+
'1 2',
2526
'obj.path',
2627
'obj.:path(\\S+).:number(\\d+)',
2728
'obj.:number(\\d+).:path(\\S+)',
2829
'obj.path.:here',
2930
'obj.(prop|path).:here',
30-
':obj.(method|prop).:here'
31-
31+
':obj.(method|prop).:here',
3232
];
3333

34-
input.forEach(function(stem){
34+
input.forEach((stem) => {
3535
parth.set(stem);
3636
});
3737

3838
// #get
39-
input = [
39+
const getInput = [
4040
'1',
4141
'2',
4242
'1 2',
@@ -47,23 +47,26 @@ input = [
4747
'get weekend/baby?query=string#hash user.10.beers',
4848
'get /weekend/baby?query=string#hash user.10.beers now',
4949
'get /user/view/#hash',
50-
'post /user/page/photo?query=name&path=tree#hash'
50+
'post /user/page/photo?query=name&path=tree#hash',
5151
];
5252

5353
console.log(' -- parth.get -- ');
54-
input.forEach(function(stem, index){
55-
result = parth.get(stem);
54+
getInput.forEach((stem, index) => {
55+
const result = parth.get(stem);
5656
console.log(' input =', stem);
5757
console.log('result =', result);
58-
console.log((input[index + 1] ? ' -- ' : '' ));
58+
console.log(getInput[index + 1] ? ' -- ' : '');
5959
});
6060

61-
if(process.argv.indexOf('-l') < 0){ return; }
62-
Object.keys(parth).forEach(function(prop){
63-
console.log(parth[prop]);
61+
if (process.argv.indexOf('-l') < 0) {
62+
process.exit(0);
63+
}
64+
65+
(Object.keys(parth) as (keyof typeof parth)[]).forEach((prop) => {
66+
console.log((parth as Record<string, unknown>)[prop]);
6467
console.log(' --\n');
6568
});
6669

67-
parth.regex.forEach(function(re){
70+
parth.regex.forEach((re) => {
6871
console.log(re.stem);
6972
});

index.js

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

jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @type {import('jest').Config} */
2+
export default {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
testMatch: ['**/test/**/*.test.ts'],
6+
moduleFileExtensions: ['ts', 'js', 'json'],
7+
collectCoverageFrom: ['src/**/*.ts', '!src/**/*.d.ts'],
8+
};

lib/util.js

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

0 commit comments

Comments
 (0)