JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 11879
  • Score
    100M100P100Q136465F
  • License MIT

JavaScript library.

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 ms

const 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 for get request, or base64

download('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 height

smoothScroll(
  // 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
);

Create independent scrolling methods

import { createSmoothScroll } from '@vavt/util';
const smoothScroll = createSmoothScroll();

throttle

Default delay of 200 ms

const handler = throttle(() => {
  // Do something
}, 100);

searchToObj

Convert location.search to object

searchToObj('?age=18&name=lili&h=1&h=2');
// { age: 18, name: 'lili', h: [1, 2] }

objToSearch

Convert object to location.search

objToSearch({ age: 18, name: 'lili', h: [1, 2] });
// 'age=18&name=lili&h=1&h=2'

objectSort

Sort object arrays by keyword

objectSort(
  [
    { name: 'F', age: 25 },
    { name: 'D', age: null },
    { name: 'E', age: 20 },
    { name: 'H', age: 30 },
    { name: 'A', age: undefined },
    { name: 'J', age: 'b' },
    { name: 'K', age: 'c' },
    { name: 'I', age: 'a' },
    { name: 'B', age: undefined },
    { name: 'G', age: 25 },
    { name: 'C', age: undefined }
  ],
  (item) => item.age
);
// [
//   { name: 'A', age: undefined },
//   { name: 'B', age: undefined },
//   { name: 'C', age: undefined },
//   { name: 'D', age: null },
//   { name: 'E', age: 20 },
//   { name: 'F', age: 25 },
//   { name: 'G', age: 25 },
//   { name: 'H', age: 30 },
//   { name: 'I', age: 'a' },
//   { name: 'J', age: 'b' },
//   { name: 'K', age: 'c' }
// ];

draggingScroll

Dragging and scrolling element while holding it down.

const removeListener = draggingScroll(document.getElementById('id'));

// removeListener()

uuid

Generate a string of random characters.

console.log(uuid());
// lmsimogsk7pukfcia4

isNumber

To determine whether a string is a number, Scientific notation will also be considered as a number.

console.log(isNumber('0.23e-1'));
// true

...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