Skip to content

Commit

Permalink
Merge pull request #12 from Flcwl/feat/unext
Browse files Browse the repository at this point in the history
Feat/unext
  • Loading branch information
Flcwl authored Oct 16, 2022
2 parents 1bf6d0d + 312cff3 commit 62b60f1
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 59 deletions.
5 changes: 0 additions & 5 deletions .changeset/honest-seas-look.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/rich-toes-hear.md

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
id: changesets
uses: changesets/action@v1
with:
publish: pnpm release
version: pnpm version
publish: pnpm release
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
14 changes: 14 additions & 0 deletions packages/unext/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# unext

## 2.0.1

### Patch Changes

- removeOne

## 2.0.0

### Patch Changes

- a18fd24: alpha.1
- 977d617: throttle
6 changes: 4 additions & 2 deletions packages/unext/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"name": "unext",
"version": "2.0.0-alpha.0",
"version": "2.0.1",
"description": "A modern web utils collection using esnext.",
"directories": {
"lib": "lib"
},
"files": ["lib"],
"files": [
"lib"
],
"main": "lib/cjs/index.js",
"module": "lib/esm/index.js",
"types": "lib/types/*.d.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/unext/src/array/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from "./for-count";
export * from "./map-range";
export * from "./normalize-array";
export * from "./uniq-by";
export * from "./remove-one";
15 changes: 15 additions & 0 deletions packages/unext/src/array/remove-one.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { AnyArray } from "../types";

/**
* Remove item from an array
*/
export const removeOne = <T>(list: T[], removed: T) => {
const result = [...list];
const index = result.findIndex((item) => item === removed);

if (index !== -1) {
result.splice(index, 1);
}

return result;
};
14 changes: 7 additions & 7 deletions packages/unext/src/assertion/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from '../array/is'
export * from '../dom/is'
export * from '../func/is'
export * from '../nullish/is'
export * from '../number/is'
export * from '../object/is'
export * from '../string/is'
export * from "../array/is";
export * from "../dom/is";
export * from "../func/is";
export * from "../nullish/is";
export * from "../number/is";
export * from "../object/is";
export * from "../string/is";
21 changes: 12 additions & 9 deletions packages/unext/src/func/throttle.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { AnyFunc } from "../types"
import { AnyFunc } from "../types";

/**
* throttle optimization
*/
export const throttle = <T extends AnyFunc>(callback: T, timeout: number): T => {
let timer: undefined | number | NodeJS.Timeout = undefined
export const throttle = <T extends AnyFunc>(
callback: T,
timeout: number
): T => {
let timer: undefined | number | NodeJS.Timeout = undefined;

return function (...args: any[]) {
if (timer) return
if (timer) return;

timer = setTimeout(() => {
timer = undefined
callback.apply(null, args)
}, timeout)
} as T
}
timer = undefined;
callback.apply(null, args);
}, timeout);
} as T;
};
26 changes: 13 additions & 13 deletions packages/unext/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export * from './array'
export * from './assertion'
export * from './dom'
export * from './env'
export * from './func'
export * from './nullish'
export * from './number'
export * from './object'
export * from './react'
export * from './server'
export * from './string'
export * from './tree'
export * from './types'
export * from "./array";
export * from "./assertion";
export * from "./dom";
export * from "./env";
export * from "./func";
export * from "./nullish";
export * from "./number";
export * from "./object";
export * from "./react";
export * from "./server";
export * from "./string";
export * from "./tree";
export * from "./types";
18 changes: 9 additions & 9 deletions packages/unext/src/object/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export * from './is'
export * from './clone'
export * from './get-nested'
export * from './set-nested'
export * from './get-object-type'
export * from './has-own-prop'
export * from './merge'
export * from './object-to-paths'
export * from './to-string'
export * from "./is";
export * from "./clone";
export * from "./get-nested";
export * from "./set-nested";
export * from "./get-object-type";
export * from "./has-own-prop";
export * from "./merge";
export * from "./object-to-paths";
export * from "./to-string";
2 changes: 1 addition & 1 deletion packages/unext/src/string/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './is'
export * from "./is";
14 changes: 7 additions & 7 deletions packages/unext/src/tree/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './clone'
export * from './crud'
export * from './filter-tree'
export * from './flatten'
export * from './get'
export * from './types'
export * from './visit-tree'
export * from "./clone";
export * from "./crud";
export * from "./filter-tree";
export * from "./flatten";
export * from "./get";
export * from "./types";
export * from "./visit-tree";

0 comments on commit 62b60f1

Please sign in to comment.