Package Exports
- @vavt/util
- @vavt/util/lib/cjs/index.cjs
- @vavt/util/lib/es/index.mjs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@vavt/util) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
vavt-util
English | 中文
A JavaScript library.
yarn add @vavt/util
# or
npm i @vavt/util
Usage
deepClone
: Can be used for most basic reference types(Map
,Set
,RegExp
,Date
)const newObj = deepClone({ a: 1 });
debounce
: Default delay of 200 msconst handler = debounce(() => { // Do something }, 100);
linkTo
: Open a new page.linkTo('https://github.com/imzbf/vavt-util', { // Open on a new window, default true _blank: false, // Access opener, default true nofollow: false });
download
:Only can be used forget
request, or base64download('https://github.com/imzbf/vavt-util/archive/refs/tags/v1.0.0.zip', 'v1.0.0.zip'); download('data:image/svg+xml,xxxxx', 'v1.0.0.png');
smoothScroll
: Smooth scrolling to specified heightsmoothScroll( // Scrolling element document.documentElement, // Scroll to 100px 100, // Callback at the end of scrolling () => { console.log('end'); }, // Whether to delay the execution of the callback at the end of the scrolling, defalut 100ms 50 );
throttle
: Default delay of 200 msconst handler = throttle(() => { // Do something }, 100);
searchToObj
: Convertlocation.search
to objectsearchToObj('?age=18&name=lili&h=1&h=2'); // { age: 18, name: 'lili', h: [1, 2] }
objToSearch
: Convert object tolocation.search
objToSearch({ age: 18, name: 'lili', h: [1, 2] }); // 'age=18&name=lili&h=1&h=2'
objectSort
: Sort object arrays by keywordobjectSort( [ { name: 'B', age: 17 }, { name: 'A', age: 13 }, { name: 'D', age: 27 }, { name: 'C', age: 23 } ], (item) => item.age ); // [ // { name: 'A', age: 13 }, // { name: 'B', age: 17 }, // { name: 'C', age: 23 }, // { name: 'D', age: 27 } // ];
...More to be updated
Develop
yarn dev
Build
# build es\cjs\umd
yarn build
# build es
yarm build:es
Folder
/dev // Debug code
/packages // Source code of utils
/xxx // Item of utils
/index.ts // Exported entry