Skip to content

Commit 030bdd3

Browse files
author
毕宇旗
committed
feat: finish main logic
0 parents  commit 030bdd3

24 files changed

+779
-0
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Editor configuration, see http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[*.md]
13+
max_line_length = off
14+
trim_trailing_whitespace = false

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
dist
3+
coverage
4+
lib

.eslintrc.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es2021: true,
5+
node: true
6+
},
7+
parserOptions: {
8+
ecmaVersion: 12,
9+
sourceType: 'module'
10+
},
11+
parser: '@typescript-eslint/parser',
12+
plugins: ['@typescript-eslint', 'prettier'],
13+
extends: [
14+
'eslint:recommended',
15+
'plugin:@typescript-eslint/eslint-recommended',
16+
'prettier/@typescript-eslint',
17+
'plugin:prettier/recommended'
18+
],
19+
rules: {
20+
'prefer-const': [
21+
'error',
22+
{
23+
destructuring: 'any',
24+
ignoreReadBeforeAssign: false
25+
}
26+
],
27+
'no-unused-vars': 0
28+
}
29+
}

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.DS_Store
2+
node_modules
3+
dist
4+
coverage
5+
lib
6+
7+
package-lock.json
8+
yarn.lock
9+
10+
# local env files
11+
.env.local
12+
.env.*.local
13+
14+
# Log files
15+
npm-debug.log*
16+
yarn-debug.log*
17+
yarn-error.log*
18+
pnpm-debug.log*
19+
20+
# Editor directories and files
21+
.idea
22+
.vscode
23+
*.suo
24+
*.ntvs*
25+
*.njsproj
26+
*.sln
27+
*.sw?

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dist
2+
lib
3+
node_modules
4+
package.json
5+
yarn.lock

.prettierrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
singleQuote: true,
3+
printWidth: 100,
4+
proseWrap: 'never',
5+
semi: false,
6+
trailingComma: 'none',
7+
arrowParens: 'avoid'
8+
}

LICENSE

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

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Welcome to @ifake/easy-polling 👋
2+
![Version](https://img.shields.io/npm/v/@ifake/easy-polling)
3+
![Npm Bundle Size](https://img.shields.io/bundlephobia/min/@ifake/easy-polling)
4+
![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
5+
6+
> The Class used to compute the next step of data.
7+
8+
The scaffolding for this project is from [pkg](https://github.com/ifakejs/pkg)
9+
10+
### 🏠 [Homepage](https://github.com/ifakejs/easy-polling)
11+
12+
### Usage
13+
```sh
14+
import { EasyPolling } from "@ifake/easy-polling";
15+
16+
const instance = new EasyPolling({
17+
source: [param1, param2, param3...],
18+
intervalTime: 2000 // 毫秒
19+
type: 'single' || 'double'
20+
returnCount: 2 // 每次返回的数据大小
21+
})
22+
instance.observe((data) => {
23+
// 根据间隔时长,返回对应的内容
24+
})
25+
instance.start()
26+
// stop
27+
instance.stop()
28+
29+
// update intervalTime
30+
instance.updateIntervalTime(5000)
31+
```
32+
33+
## Author
34+
35+
👤 **BiYuqi**
36+
## 🤝 Contributing
37+
38+
Contributions, issues and feature requests are welcome!
39+
40+
Feel free to check [issues page](https://github.com/ifakejs/easy-polling/issues).
41+
42+
## Show your support
43+
44+
Give a ⭐️ if this project helped you!
45+
46+
## 📝 License
47+
48+
This project is [MIT](https://github.com/ifakejs/easy-loop/blob/master/LICENSE) licensed.
49+
50+
***
51+
_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_

__test__/Q.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Q } from "../src/Q"
2+
3+
describe("Q", () => {
4+
let instance: Q
5+
beforeEach(() => {
6+
instance = new Q()
7+
})
8+
it('enqueue ', () => {
9+
instance.enqueue(1)
10+
expect(instance.queue).toEqual([1])
11+
})
12+
13+
it('enqueue ', () => {
14+
instance.enqueue(1)
15+
expect(instance.dequeue()).toEqual(1)
16+
})
17+
18+
it('front ', () => {
19+
instance.enqueue(2)
20+
instance.enqueue(1)
21+
expect(instance.front()).toEqual(2)
22+
})
23+
24+
it('clear ', () => {
25+
instance.enqueue(2)
26+
instance.enqueue(1)
27+
instance.clear()
28+
expect(instance.queue).toEqual([])
29+
})
30+
31+
it('isEmpty ', () => {
32+
expect(instance.isEmpty).toEqual(true)
33+
instance.enqueue(2)
34+
expect(instance.isEmpty).toEqual(false)
35+
})
36+
})

__test__/chunk.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { chunk } from "../src/chunk"
2+
3+
describe("chunk", () => {
4+
it('should return correct error message', () => {
5+
try {
6+
// @ts-ignore
7+
chunk("", 2)
8+
} catch (e) {
9+
expect(e.message).toBe("Required an array.")
10+
}
11+
});
12+
it('should split array correct', () => {
13+
expect(chunk([1, 2, 3, 4, 5], 2)).toEqual([ [ 1, 2 ], [ 3, 4 ], [ 5 ] ])
14+
});
15+
})

0 commit comments

Comments
 (0)