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

common-a2dev

v0.1.3

Published

gather sometimes need.

Downloads

14

Readme

common-a2dev

gather sometimes need.

usage

var common = require("common-a2dev")

let v = []
if (common.isArray(v)) {
  console.log("it's array")
} else {
  console.log("it's not array")
}

methods

existsArg (v)

check args isExists

common.existsArg(undefined) // false
common.existsArg(1) // true
common.existsArg(null) // true

canNumber (v)

check value it's can change number

common.canNumber (1) // true
common.canNumber ("1") // true
common.canNumber ("a") // false
common.canNumber ("1a") // false

hasDataObject (v)

check value it's false or when value is object not have data

common.hasDataObject ({}) // false
common.hasDataObject ([]) // false
common.hasDataObject ([0]) // true
common.hasDataObject () // false
common.hasDataObject (0) // false

valueObject (object, key, def)

get value from object

common.valueObject ({a: 1}, "a", 2) // 1
common.valueObject ({a: 1}, "b", 2) // 2

copyObject (object)

value copy object

var obj1 = {a: 1}
var obj2 = common.copyObject (obj1) // 1
obj2.a = 2

console.log(obj1) // {a: 1}
console.log(obj2) // {a: 2}

matchUrl (str, options = {})

get urls by string

common.matchUrl ("http://exsample.com is url. second url is http://exsample2.com") // ["http://exsample.com", "http://exsample2.com"]

options

  • isDeleteEscape: boolean
    • if it's true. delete escape string.

fillObject (obj, sample, options = {})

fill data by sample

var obj = {a: 1}
var options = {
  isPrune: false
}
var obj2 = common.fillObject (obj, {b: 2}, options) // {a: 1, b: 2}

options

  • isPrune: boolean
    • if it's true. run prneOjbect after fillObject

pruneObject (obj, sample, options = {})

prune data from obj not exists sample value

var obj = {a: 1, b: 2}
var options = {
  isPrune: false
}
var obj2 = common.pruneObject (obj, {b: 2}, options) // {b: 2}

randomInt (min, max)

get randomInt

common.randomInt(1, 5) // 1-5

typeString (v)

get value type from class

common.typeString(1) // '[object Number]'
common.typeString("1") // '[object String]'
common.typeString([]) // '[object Array]'
common.typeString({}) // '[object Object]'

isObject (v)

check value is object corectly

common.isObject(1) // false
common.isObject("1") // false
common.isObject(null) // false
common.isObject([]) // false
common.isObject({}) // true

isArray (v)

check value is object corectly

common.isArray(1) // false
common.isArray("1") // false
common.isArray(null) // false
common.isArray([]) // true
common.isArray({}) // false

isObjectArray (v)

check value is object or array. if it's null return is false.

common.isObjectArray(1) // false
common.isObjectArray("1") // false
common.isObjectArray(null) // false
common.isObjectArray([]) // true
common.isObjectArray({}) // true

getArgumentNode ()

get node binary path currentry run.

common.getArgumentNode() // '/usr/local/Cellar/node/8.1.2/bin/node'

NOTE: please use only when cli.

getArgumentCurrent ()

get node script path currentry run.

common.getArgumentCurrent() // '/path/to/current/${script.js}'

NOTE: please use only when cli.

getArgumentValue (index)

get value from argument.

node sample.js 1 2 3
common.getArgumentValue(0) // 1
common.getArgumentValue(2) // 3

addNodePathEnv (path)

add node path. for Environment

common.addNodePathEnv("/path/to/node") // NODE_PATH: "${NODE_PATH};/path/to/node"

getMatches (values, pattern)

get match string from multi string by pattern.

common.getMatches(["abcdefgabcxyz", "hijxyz"], /cd/) // [ 'cd' ]
common.getMatches(["abcdefgabcxyz", "hijxyz"], /xy/) // [ 'xy', 'xy' ]
common.getMatches(["abcdefgabcxyz", "hijxyz"], /[a-z]{2}/) // [ 'ab', 'hi' ]
common.getMatches(["abcdefgabcxyz", "hijxyz"], /[a-z]{2}/g) // [ 'ab', 'cd', 'ef', 'ga', 'bc', 'xy', 'hi', 'jx', 'yz' ]

getMaxLengthStr (strings)

get max length from strings

common.getMaxLengthStr(["1", "333", "22"]) // 3

fillStr (str, length, fill = '0')

fill string fill

common.fillStr(123, 6) // '00123'
common.fillStr(123, 2) // '23'
common.fillStr(123, 6, "ZY") // 'ZYZ123'
common.fillStr("abc", 7, "ZY") // 'ZYZYabc'

NOTE: when fill's value is multi. stacking from the front.

betweenStr (str, prefix, suffix, options = {})

get string btween prefix and suffix

common.betweenStr("abcdefghijklmn", "cd", "kl") // 'efghij'
common.betweenStr("abcdefghijklmn", "ZZ", "ZZ") // ''
common.betweenStr("abcdefghijklmn", "cd", "kl", {isDetail: true}) // [ 'cdefghijkl', 'efghij', index: 2, input: 'abcdefghijklmn' ]

options

  • isDetail: boolean
    • if it's true. return match object.

escapeRegStr (str)

escape string for regExp

disallowStringFileName ()

get disallow strings for filename.

common.disallowStringFileName () // [ '\\', '/', ':', '*', '?', '"', '<', '>', '|' ]

replaceDisallowStringFileName (str, replace = '')

replace disallow string from string for filename of filesystem.

common.disallowStringFileName () // [ '\\', '/', ':', '*', '?', '"', '<', '>', '|' ]

Date.format

var d = new Date
d.format('YYYY-MM-DDTHH:mm:SS') // '2018-03-17T13:54:38'

NOTE: automaticaly set prototype