Skip to content

Commit

Permalink
docs(readme): 修改文档
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherso1a committed Oct 22, 2019
1 parent 97999ab commit e157ff8
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 6 deletions.
70 changes: 69 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,82 @@
```html
<script src="js/afl.min.js"></script>
<script>
afl.sum([1,2,3]) //6
afl.shuffle([1,2,3]) //[2,1,3]
afl.object2map({
a: 1,
b: 2
}) //Map(2) {"a" => 1, "b" => 2}
afl.parseQuery('a=1&b=2') //{a: "1", b: "2"}
afl.stringifyQuery({a:1,b:2}) //a=1&b=2
afl.objectDig({a:{b:{c:{d:4}}}},'d') //4
</script>
```

## 描述

初步打算封装一些自己造的轮子

## API

### Array

#### shuffle

洗牌算法,用于随机打乱数组

```js
afl.shuffle([1,2,3]) //[2,1,3]
```

### Function

#### throttle

节流函数

```js
let count = {n:0}
let thottled = afl.throttle(count=> ++count.n,500)
setTimeout(()=>{
for(let i = 0; i < 10 ; i++){
thottled(count)
}
console.log(count.n)//1
},1000)
```

### Object

#### object2map

对象转为Map

```js
afl.object2map({
a: 1,
b: 2
}) //Map(2) {"a" => 1, "b" => 2}
```

#### objectDig

查找对象中特定key值

```js
afl.objectDig({a:{b:{c:{d:4}}}},'d') //4
```

### String

#### parseQuery && stringifyQuery

序列化或解析search字符串

```js
afl.parseQuery('a=1&b=2') //{a: "1", b: "2"}
afl.stringifyQuery({a:1,b:2}) //a=1&b=2
```

## 项目说明

**1.** `commit`提交规范,请使用`npm run commit` 进行提交
Expand Down
2 changes: 1 addition & 1 deletion __tests__/function/trodeb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { throttle } from '../../src/function/throttle';
test('throttle', () => {
let count1: Number = 0;
let count2: Number = 0;
let fn:Function = n => n++;
let fn: Function = n => n++;
let throttled = throttle(fn, 20);
for (let i = 0; i < 5; i++) {
setTimeout(() => {
Expand Down
6 changes: 3 additions & 3 deletions __tests__/object/objectDig.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { objectDig } from '../../src/object/objectDig';

test('dig in object, find the value you want', () => {
const t = {a:{b:{c:{d:4}}}}
const t = { a: { b: { c: { d: 4 } } } };
//通常 你需要 t.a.b.c.d
//现在 你可以 objectDig(t,"d")
expect(objectDig(t,"d")).toBe(4);
});
expect(objectDig(t, 'd')).toBe(4);
});
2 changes: 1 addition & 1 deletion dist/afl.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e157ff8

Please sign in to comment.