Skip to content

Commit 9685d2e

Browse files
committed
write with ts
1 parent e667578 commit 9685d2e

11 files changed

+5032
-128
lines changed

.babelrc

-9
This file was deleted.

.eslintrc

-29
This file was deleted.

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
node_modules
2-
.env
3-
dist
42
lib
3+
coverage
4+
.DS_Store

LICENSE.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2015 Chris Pearce <[email protected]>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

__test__/index.spec.ts

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import isMatch from '../src'
2+
3+
describe('FOO', () => {
4+
it('should return true if matches words', () => {
5+
const arr = ['zhong', 'guo', 'zhong', 'che']
6+
expect(isMatch(arr, 'zhong')).toBeTruthy()
7+
expect(isMatch(arr, 'guo')).toBeTruthy()
8+
expect(isMatch(arr, 'zhongg')).toBeTruthy()
9+
expect(isMatch(arr, 'guozhong')).toBeTruthy()
10+
})
11+
12+
test('should return true if matches words case-insensitive', () => {
13+
const arr = ['zhong', 'guo', 'zhong', 'che']
14+
expect(isMatch(arr, 'Zhong')).toBeTruthy()
15+
expect(isMatch(arr, 'GUO')).toBeTruthy()
16+
expect(isMatch(arr, 'ZHONGG')).toBeTruthy()
17+
expect(isMatch(arr, 'guoZhong')).toBeTruthy()
18+
})
19+
20+
test('should matches first letter of each word from beginning', () => {
21+
const arr = ['zhong', 'guo', 'zhong', 'che']
22+
expect(isMatch(arr, 'ZG')).toBeTruthy()
23+
expect(isMatch(arr, 'ZGZC')).toBeTruthy()
24+
expect(isMatch(arr, 'GZ')).toBeFalsy()
25+
})
26+
27+
test('should match from the beginning', () => {
28+
const arr = ['zhong', 'guo', 'zhong', 'che']
29+
const config = { wordFromStart: true }
30+
expect(isMatch(arr, 'zhong', config)).toBeTruthy()
31+
expect(isMatch(arr, 'guo', config)).toBeFalsy()
32+
expect(isMatch(arr, 'zhongg', config)).toBeTruthy()
33+
expect(isMatch(arr, 'guozhong', config)).toBeFalsy()
34+
})
35+
36+
test('should matches first letter of each word', () => {
37+
const arr = ['zhong', 'guo', 'zhong', 'che']
38+
const config = { letterFromStart: false }
39+
expect(isMatch(arr, 'ZG', config)).toBeTruthy()
40+
expect(isMatch(arr, 'ZGZC', config)).toBeTruthy()
41+
expect(isMatch(arr, 'GZ', config)).toBeTruthy()
42+
})
43+
44+
test('should matches first letter of each word', () => {
45+
const arr = ['bin', 'jiang', 'ji', 'tuan']
46+
expect(isMatch(arr, 'jituan')).toBeTruthy()
47+
})
48+
49+
test('should matches chinese', () => {
50+
const arr = ['滨', '江', '集', '团']
51+
expect(isMatch(arr, '滨江')).toBeTruthy()
52+
expect(isMatch(arr, '集团')).toBeTruthy()
53+
expect(isMatch(arr, '滨江集团')).toBeTruthy()
54+
})
55+
});

jest.config.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
transform: {
4+
"^.+\\.tsx?$": "ts-jest"
5+
},
6+
moduleFileExtensions: [
7+
"ts",
8+
"tsx",
9+
"js",
10+
"jsx",
11+
"json",
12+
"node",
13+
],
14+
testRegex: '(/__test__/.*|(\\.|/)(test|spec))\\.(ts|js)x?$',
15+
coverageDirectory: 'coverage',
16+
collectCoverageFrom: [
17+
'src/**/*.{ts,tsx,js,jsx}',
18+
'!src/**/*.d.ts',
19+
],
20+
};

0 commit comments

Comments
 (0)