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

@nsea/util

v1.0.2

Published

utils

Downloads

5

Readme

Usage

Install with npm

npm i nscutils
const Utils = require("nscutils");

the utils for Array

sort

const Utils = require("nscutils");
/**
 * @example utils.Array.order([{value:10},{value:20}],'desc','value')
 * @example utils.Array.order([10,20],'desc')
 * @param {Array} array source
 * @param {String} type sort type asc/desc  default asc
 * @param {String} column
 * @returns {Array} sorted Array
 */
const res = Utils.Array.order(array, type, column);

de-duplication

const Utils = require("nscutils");
/**
 * @example utils.Array.unique([{name:'zs'},{name:'zs'}],'name')
 * @example utils.Array.unique([10,10])
 * @param {Array} array
 * @param {String} column
 * @returns {Array}
 */
const res = Utils.Array.unique(array, column);

the utils for String

removeHTML

const Utils = require("nscutils");
/**
 * @param {String} html
 * @returns {String}
 * @example 'string'=Utils.String.removeHTML(`<span class="gray7 mr20">string</span>`)
 */
const res = Utils.String.removeHTML(html);

cut off string and append in the end

const Utils = require("nscutils");
/**
 *  subString(`sadfsdafsd`,2,'...')
 * @param {String} val
 * @param {Number} len
 * @param {String} suffix
 * @example 'sa...'=Utils.String.subString(`sadfsdafsd`,2,'...')
 * @returns {String}
 */
const res = Utils.String.subString(val, len, suffix);

String->Float

const Utils = require("nscutils");
/**
 * @param {String} val
 * @param {Number} len  decimal length
 * @param {Boolean} fill   default =true
 * @returns {String}
 * @example '1.20'=Utils.String.toFixed('1.2',2)
 * @example '1.2'=Utils.String.toFixed('1.2',2,false)
 */
const res = Utils.String.toFixed(val, len, fill);

delete f&p space

const Utils = require("nscutils");
/**
 * @param {String} val
 * @returns {String}
 * @example "das das"=nscutils.String.trim(`   das das  `)
 */
const res = Utils.String.trim(val);

replaceAll

const Utils = require("nscutils");
/**
 * @param {String} val
 * @param {String} replacestr
 * @param {String} newstr
 * @returns {String}
 * @example "a|aa|aa"=nscutils.String.replaceAll(`asaasaa`,'s','|')
 */
const res = Utils.String.replaceAll(val, replacestr, newstr);

String->Date

const Utils = require("nscutils");
/**
 * @param {String} val
 * @param {String} split  '-'|'/'|... required default '-'
 * @returns {Date}
 * @example nscutils.String.toDate(`2015-01-01`,'-')
 */
const res = Utils.String.toDate(val, split);

the utils for Date

format

const Utils = require("nscutils");
/**
 * @param {Date} date
 * @param {String} fmt   yyyy-MM-dd
 * "y+":year
 * "M+":month
 * "q+":quarter
 * "d+": day
 * "h+": hour
 * "m+": minute
 * "s+":second
 * "S": Millisecond
 * @returns {String}
 * @example "2018-11-14"=nscutils.Date.format(new Date(),'yyyy-MM-dd')
 */
const res = Utils.Date.format(date, fmt);

countdown now -> date

const Utils = require("nscutils");
/**
 * @param {Date} date 2019-01-08 00:00:00
 * @returns {String}
 * @example "2018-11-14"=nscutils.Date.format(2019-01-08 00:00:00)
 */
const res = Utils.Date.Countdown(date);

the utils for Object/Array

copy

const Utils = require('nscutils');
/**
 * @param {Boolean} isDeep
 * @param {Object/Array} target
 * @param {Object/Array} src  one or more Object
 * @returns {Object/Array}
 * @example {a:1,b:2,d:4,f:5}=nscutils.Object.extend(true,{},{a:1,b:2},{d:4},{f:5})
 * also worked in Array
 * @example [4,1,5,4]nscutils.Object.extend(true,[],[1,2,3,4],[4,1,5])
 * @example [1,2,3,4]nscutils.Object.extend(true,[],[1,2,3,4])
 */
const res = Utils.Object.extend(isDeep,target,src...);

the utils for color

rgb->binary

const Utils = require("nscutils");
/**
 * @param {String} color
 * @returns {String}
 */
const res = Utils.Color.rgb2binary(color);