GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - planjs/utils: 🔧 ćźžç”šć·„ć…·é›†ćˆ

BranchesTags
Open more actions menu

Latest commit

 

History

347 Commits
347 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.husky
.husky
 
 
__tests__
__tests__
 
 
fixtures
fixtures
 
 
scripts
scripts
 
 
src
src
 
 
.editorconfig
.editorconfig
 
 
.eslintignore
.eslintignore
 
 
.eslintrc.js
.eslintrc.js
 
 
.gitignore
.gitignore
 
 
.npmrc
.npmrc
 
 
.prettierignore
.prettierignore
 
 
.prettierrc.js
.prettierrc.js
 
 
.stanrc.ts
.stanrc.ts
 
 
.travis.yml
.travis.yml
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
commitlint.config.js
commitlint.config.js
 
 
jest.config.js
jest.config.js
 
 
package.json
package.json
 
 
pnpm-lock.yaml
pnpm-lock.yaml
 
 
tsconfig.base.json
tsconfig.base.json
 
 
tsconfig.docs.json
tsconfig.docs.json
 
 
tsconfig.json
tsconfig.json
 
 
typedoc.json
typedoc.json
 
 

Repository files navigation

utils

npm npm action
NPM

🔧 contactInfoDefault doc

Installation

npm i @planjs/utils

Usage

import {
  delay,
  retry,
  pTry,
  sequenceChain,
  nextTick,
  range,
  REG_TEL_PHONE,
  eventCenter,
  TimeoutMap,
} from '@planjs/utils';

// promise utils
async function main() {
  await delay(100);
  function fetchData() {
    return Promise.reject(new Error('testing'));
  }
  await retry(fetchData, { maxAttempts: 3, delayMs: 500 })();
}

const pool = asyncPool({ maxConcurrency: 10 });

const randArr = range(1, 10);

nextTick(async () => {
  const [err, res] = await pTry(main());
  if (!err) {
    console.log(res);
  }
  let start = Date.now();
  await Promise.all(randArr.map((v) => pool.executor(delay(v))));
  // The timer has an accuracy problem
  if (Date.now() - start + 1 >= Math.max(...randArr)) {
    console.log('concurrency');
  }
  const count = (a = 0) => ++a;
  const val = await sequenceChain([...range(0, 10).map((v) => [count])])();
  console.log(val); // 11
});

// commonly used regex
REG_TEL_PHONE.test('132xxxxxxx'); // false

// event center
eventCenter.on('log', console.log);
eventCenter.trigger('log', 'planjs');

// ext obj
const timeoutMap = new TimeoutMap({
  timeout: 200,
  passiveDeletion: true,
  onTimeout(k, v) {
    console.log(`expired key [${k}], val [${v}]`);
  },
});
timeoutMap.set('name', 'fupengl');
delay(201).then(() => timeoutMap.get('name')); // null

About

🔧 ćźžç”šć·„ć…·é›†ćˆ

planjs.github.io/utils/

Topics

js-utilspromisekitts-utilstypescriptweb-kit

Resources

Readme
MIT license
Activity
Custom properties

Stars

16 stars

Watchers

1 watching

Forks

4 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.