him-ich-helpers
A helpers for personal use.
Last updated a year ago by him-ich .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install him-ich-helpers 
SYNC missed versions from official npm registry.

him-ich-helpers

A helpers for personal use.

Installation

Using npm:

npm install him-ich-helpers

promiseDelay(ms = 500) : {Promise}

Delay for some sort of seconds and do the next promise

var { promiseDelay } = require('him-ich-helpers');

const fnPromise = () => {
    return new Promise(resolve => {
        const number = Math.random();
        
        resolve(number);
    });
};

promiseDelay()
    .then(() => {
        return fnPromise();
    })
    .then(number => {
        console.log(number);
    });

promiseRetry(fn, delay = 500, limit = 3) : {Promise}

Retry the promise again when it's failed with some sort of delay in ms and limit of times

var { promiseRetry } = require('him-ich-helpers');

const fnPromise = () => {
    return new Promise((resolve, reject) => {
        const number = Math.random();
        
        // this promise will failed sometimes
        if (number > 0.1) {
            reject(number);
        } else {
            resolve(number);
        }
    });
};

promiseRetry(fnPromise)
    .then(number => {
        console.log(number);
    })
    .catch(number => {
        console.error(number);
    });

now() : {string}

Get today's datetime

var { now } = require('him-ich-helpers');

console.log(now()); // 2019-05-16 14:53:38

today() : {string}

Get today's date

var { now } = require('him-ich-helpers');

console.log(now()); // 2019-05-16

toLocalDateTime(datetime = new Date()) : {string}

Convert UTC Datetime to Local Datetime

var { toLocalDateTime } = require('him-ich-helpers');

console.log(toLocalDateTime('2019-05-07T08:51:00Z')); // 2019-05-07 14:51:00

toLocalDate(datetime = new Date()) : {string}

Convert UTC Datetime to Local Date

var { toLocalDate } = require('him-ich-helpers');

console.log(toLocalDate('2019-05-07T08:51:00Z')); // 2019-05-07

Current Tags

  • 1.0.2                                ...           latest (a year ago)

3 Versions

  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (1)
Dev Dependencies (0)
None

Copyright 2014 - 2016 © taobao.org |