npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lego-tools

v0.1.3

Published

use tools like lego.

Downloads

8

Readme

lego-tools

npm version build status coverage license

The tools library, now is support date|object|number.

Install

npm install --save lego-tools

example

demo

new version

[0.1.2] add repeat and diff function to obj (high performance)

LT.obj.repeat([1, '1', 1, 2]) => [1, '1', 2] // array length is 1000000 only use 296ms (in mac)
LT.obj.repeat([{age: 1}, {age: 1}], 'age') => [{age: 1}]

let source2 = {age: 5, name: 'Ken'}
let target2 = {age: 5, name: 'Ken',}
LT.obj.diff(source, target) => false

let source = {age: 5, name: 'Ken', address: 'test'}
let target = {age: 5, name: 'Tom', fav: 'book'}
LT.obj.diff(source, target) => {add: {fav: 'book}, delete: {address: 'test'}, keep: {age: 5}, update: {source: {name: 'Ken'}, target: {name: 'Tome'}}}

[0.1.1] add sort function to obj

LT.obj.sort([{age:1}, {age:2}], 'age:desc') => [{age:2}, {age:1}]

Usage

#num

support js to compute the times,div,plus,minus

  • function: compute(computeStr:string)
  • params: computeStr - like -> (2+5)*3+(39.9*3)\2 -> 80.85
  • return: number
  • example: LT.num.compute('(2+5)*3+(39.9*3)\2')

format the num like round,ceil,floor

  • function: format(num:string|number, targetFormat:string, type:string)
  • params: num:12.34,'12.34' | targetFormat:'.','.0','.00'... and more | type:'round','ceil','floor'
  • return: source num type
  • example: LT.num.format(12.34, '.0', 'round') => 12.3

format the num like money show

  • function: formatMoney(num:string|number, targetFormat:string(NULL), type:string(NULL))
  • params: num:1234.34,'1234.34' | targetFormat:'.','.0','.00'... and more | type:'round','ceil','floor'
  • return: string
  • example: LT.num.formatMoney(1234.34) => 1,234.34

#obj

get value or list from object/array

  • function: deepGet(data:object|array, keyStr)
  • params: data | keyStr:object -> 'detail.name.version' / array -> 'detail.age>5&sex="man"'
  • return: target vlaue/array
  • example: LT.obj.deepGet({detail: {name: 'Tom'}}, 'detail.name') => Tom

set the target object

  • function: deepSet(data:object, keyStr, vlaue:any)
  • params: date | keyStr: 'detail.name.version' | value
  • return: target object
  • example: LT.obj.deepSet({detail: {name: 'Tom'}}, 'detail.age', 10) => {detail: {name: 'Tom', age: 10}}

sort array

  • function: sort(data:array, express)
  • params: date | keyStr: 'desc/asc' or 'detail.intro.age:desc/asc'
  • return: data
  • example: LT.obj.sort([{age:1}, {age:2}], 'age:desc') => [{age:2}, {age:1}]

#date

get current date
  • function: now(targetFormat(NULL))
  • params: targetFormat:yyyy-MM-dd HH:mm:ss
  • return: date|string
  • example: LT.date.now() => Date; LT.date.now('yyyy-MM-dd') => 2018-12-20

format target date/dateStr

  • function: format(date:string|date, targetFormat)
  • params: targetFormat:yyyy-MM-dd HH:mm:ss
  • return: string
  • example: LT.date.format(new Date()|'2018-12-20 13:59:30', 'yyyy-MM-dd') //=> 2018-12-20

add years,months,days,hours,minutes,second to date

  • function: add(date:string|date, num:number, type:string, targetFormat:string)
  • params: type:years,months,days,hours,minutes,second | targetFormat:yyyy-MM-dd HH:mm:ss
  • return: source date type
  • example: LT.date.add('2018-12-20 12:29:30'|new Date(), 1, 'months', 'yyyy-MM-dd HH:mm:ss') => 2019-01-20 12:29:30

subtract years,months,days,hours,minutes,second from date

  • function: subtract(date:string|date, num:number, type:string, targetFormat:string(NULL))
  • params: type:years,months,days,hours,minutes,second | targetFormat:yyyy-MM-dd HH:mm:ss
  • return: source date type
  • example: LT.date.subtract('2018-12-20 12:29:30'|new Date(), 1, 'months', 'yyyy-MM-dd HH:mm:ss') => 2018-11-20 12:29:30

diff two date

  • function: diff(date:string|date, date:string|date)
  • params: date
  • return: object - {days: number, hours: number, minutes: number, seconds: number}
  • example: LT.date.diff('2018-12-20 12:29:30', '2018-12-18 12:29:30') => {days: 2, hours: 0, minutes: 0, seconds: 0}

use in code:

const LT = require('lego-tools')//OR lego-tools/date
//todo
...