New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mrtujiawei/utils

Package Overview
Dependencies
Maintainers
1
Versions
600
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mrtujiawei/utils

把自己写的工具函数打包发布到npm上

  • 1.4.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6K
increased by233.05%
Maintainers
1
Weekly downloads
 
Created
Source

@mrtujiawei/utils

npm version install size npm downloads js delivr downloads

Table of Contents

Installing

Using npm:

$ npm install @mrtujiawei/utils

Using yarn:

$ yarn add @mrtujiawei/utils

Using unpkg CDN:

<script src="https://unpkg.com/@mrtujiawei/utils/dist/utils.js"></script>

Usage

note: Brower usage

const { Stack } = utils.Stack;

note: CommonJS usage

const { Stack } = require('@mrtujiawei/utils');

or

const utils = require('@mrtujiawei/utils');
const Stack = utils.Stack;

note: ESModule usage

import { Stack } from '@mrtujiawei/utils';

or

import utils from '@mrtujiawei/utils';
const Stack = utils.Stack;

Example

使用示例

Stack

import { Stack } from '@mrtujiawei/utils';

const stack = new Stack();

stack.size;         // 0
stack.isEmpty();    // true

stack.push(1);      // [1]
stack.push(2, 3);   // [1, 2, 3]
stack.size;         // 3
stack.isEmpty();    // false

stack.pop();        // 3
stack.peak();       // 2
stack.pop();        // 2
stack.peak();       // 1
stack.pop();        // 1
stack.peak();       // throw Error: StackEmptyError
stack.pop();        // throw Error: StackEmptyError

Queue

import { Queue } from '@mrtujiawei/utils';

const queue = new Queue();

queue.size;         // 0
queue.isEmpty();    // true

queue.enqueue(1);   // [1]
queue.enqueue(2);   // [1, 2]
queue.dequeue();    // 1

queue.enqueue(3);   // [2, 3]

queue.size;         // 2
queue.isEmpty();    // false
queue.dequeue();    // 2
queue.dequeue();    // 3
queue.dequeue();    // throw Error: QueueEmptyError

Lock

异步流程加锁

import { Lock, sleep }  from '@/mrtujiawei/utils';

const lock = new Lock(1);

/**
 * 异步任务只有等上次任务结束后才会开始执行下一个异步任务
 */
const run = async (value, timeout) => {
  try {
    await lock.lock();
    // 异步任务
    await sleep(timeout);
    console.log(value);
  } finally {
    lock.unLock();
  }
};

run(0, 1000);
run(1, 100);
run(2, 0);

output: 0 1 2

DateTimeTool

日期时间处理类
解析时间太复杂,没做

import { DateTimeTool }  from '@/mrtujiawei/utils';

DateTimeTool.timeFormat(new Date(), ':');       // hh:mm:ss
DateTimeTool.dateFormat(new Date(), '-');       // yyyy-mm-dd

Keywords

FAQs

Package last updated on 04 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc