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

chutils

v2.0.0

Published

Javascript utility functions to prevent arthritis

Downloads

23

Readme

chutils

Ever find yourself feeling repetitive, a bit of the coding déjà blues? While your mind may be momentarily suffering from a relapse, your fingers don't have to with these utility function designed to win back some "me" time.

Version

2.0.0

Utility List (thus far)

type

  1. shouldBe: get the "working" variable type (Thanks to Angus )
const { type: { shouldBe } } = require('chutils')

typeof null // "object"
shouldBe(null) // "null"

typeof [] // "object"
shouldBe([]) // "array"

typeof new Promise(success=>{},error=>{}) // "object"
shouldBe new Promise(success=>{},error=>{}) // "promise"

safe

  1. assign: safely assign deeply-nested properties
const { safe: { assign } } = require('chutils')

let obj = { package: 'chutils'}

obj = assign(obj, 'deeply.nested.layer', 'hi');

/*
obj = {
  package: 'chutils',
  deeply: {
    nested: {
      layer: 'hi' 
    }
  }
} 
*/
  1. get: safely get deeply-nested properties
const { safe: { get } } = require('chutils')

const obj = {
  package: 'chutils',
  deeply: {
    nested: {
      layer: 'hi' 
    }
  }
} 

get(obj,'deeply.nested.layer') // 'hi'

// even with different object notations
get(obj,'deeply["nested"].layer') // 'hi'

// no more TypeError accessing properties of undefined
obj.imaginary.layer // TypeError: Cannot read property 'imaginary' of undefined
get(obj,'imaginary.layer') // undefined

compare

  1. value: safely compare deeply-nested property value (strict comparision)
const { compare: { value } } = require('chutils')

const obj = {
  package: 'chutils',
  deeply: {
    nested: {
      layer: 'hi' 
    }
  }
} 

value(obj,'deeply.nested.layer','hi') // true

// even with different object notations
value(obj,'deeply["nested"].layer', 'hi') // true

// no more TypeError accessing properties of undefined
obj.imaginary.layer // TypeError: Cannot read property 'imaginary' of undefined
value(obj,'imaginary.layer', 'exist') // false
  1. shouldBe: safely compare deeply-nested property value to it's type.shouldBe value
const { compare: { shouldBe } } = require('chutils')

const obj = {
  package: 'chutils',
  deeply: {
    nested: {
      layer: 'hi',
      arr: [1,2,3]
    }
  },
  promiseObj: Promise.resolve()
} 

shouldBe(obj, 'deeply.nested["arr"]','array') // true
shouldBe(obj, 'promiseObj', 'promise') // true

async

  1. dePromisify: unwraps an ES6 Promise to its nostalgic error-first callback form
const { async: { dePromisify } } = require('chutils')
const bluebird = require('bluebird')

const fs = require('fs')
const readFileAsync = bluebird.promisify(fs.readFile)
const readFileCB = dePromisify(readFileAsync)
readFileCB('someText.txt', function(err,data){
  if(err) err
  else console.log(data) // some data here
})
  1. dePromisifyAll: iterates through an object's enumerable properties and dePromisifies the functions
const { async: { dePromisifyAll } } = require('chutils')
const bluebird = require('bluebird')

let fs = bluebird.promisifyAll(require('fs'))
fs = dePromisifyAll(fs)

fs.readFileCB('someText.txt', function(err,data){
  if(err) err
  else console.log(data) // some data here
})
  1. promisify: wraps an error-first callback function into an ES6 Promise
const { async: { promisify } } = require('chutils')
const fs = require('fs')

const readFileAsync = promisify(fs.readFile)
readFileAsync('someText.txt')
.then(data=>{
  console.log(data) // some data here
})
  1. promisifyAll: iterates through an object's enumerable properties and promisifies the functions
const { async: { promisifyAll } } = require('chutils')
const fs = promisifyAll(require('fs'))

fs.readFileAsync('someText.txt')
.then(data=>{
  console.log(data) // some data here
})

Installation

Native ES6 Promises is required therefore Node v4.2.4+

$ npm i chutils

Testing

$ npm i chutils
$ cd ./node_modules/chutils
$ npm i
$ npm run test

License

MIT