JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 12957
  • Score
    100M100P100Q139455F
  • 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
    );
  • 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: '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 }
    // ];
  • draggingScroll: Dragging and scrolling element while holding it down.

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

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