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

@hoast/utils

v3.2.0

Published

Utility functions commonly used by hoast and hoast packages.

Downloads

18

Readme

@hoast/utils

Utility functions commonly used by hoast and hoast packages.

Install

npm install @hoast/utils

Usage

A list of all the files and exported functions can be seen below. Simply import by the package name followed by the file path, for example import deepAssign from '@hoast/utils/deepAssign.js'. If a file exports multiple functions the default export will be object with all the functions on it.

deepAssign.js

Deeply assign a series of objects properties together.

  • @param {Object} target Target object to assign onto.
  • @param {...Object} sources Sources to assign with.
  • @returns {Object} Target object with sources values assigned.

deepMerge.js

Deeply assign a series of arrays and or objects properties together.

  • @param {Any} target Target to merge onto.
  • @param {...Any} sources Sources to merge with.
  • @returns {Object} Target object with sources values merged.

iterateDirectory.js

Creates recursive directory iterator. Call the returned function again and again to receive a file path. Returns null when all values have been iterated over.

  • @param {String} directoryPath Absolute directory path.
  • @returns {Function} Recursive directory iterator function.

get.js

getByDotNotation

Get a value from a source by a dot seperated path.

  • @param {Object} source The object to retrieve a value from.
  • @param {String} path Dot notation string with each segment a property on the source.
  • @returns {Any} Value at path.

getByPathSegments

Get a value from a source by an array seperated path.

  • @param {Object} source The object to retrieve a value from.
  • @param {Array<String>} path Array of strings with each segment a property on the source.
  • @returns {Any} Value at path.

has.js

Check if an object has the required properties.

  • @param {Object} value Value to check.
  • @param {Array} propertyNames Array of property names.
  • @returns {Boolean} Whether the value is an object and the properties exist.

instantiate.js

Instantiate a value. If the value is an array the first item is assumed to be the value and the others become parameters given to the constructor.

  • @param {Any} value Value to import and or instantiate. A string will be dynamically imported.
  • @returns {Object} The imported and instantiated object.

is.js

isClass

Checks if value is a class.

  • @param {Any} value Value to check.
  • @returns {Boolean} Whether the value is a class.

isObject

Check whether the value is an object.

  • @param {Any} value Value of unknown type.
  • @returns {Boolean} Whether the value is an object.

Logger.js

Logger class usefull for only allowing messages to be send to the console of the right level is set.

  • constructor Create logger instance.

    • @param {Number} level Log level.
    • @param {String} prefix Prefix of logged messages.
  • getLevel Get log level value.

    • @returns {Number} log level value.
  • setLevel Set log level value.

    • @param {Number} level Log level value.
  • getPrefix Get log prefix value.

    • @returns {String} Log prefix value.
  • setPrefix Set log prefix value.

    • @param {Number} prefix Log prefix value.
  • info Logs info message to console if level is greater than 2.

    • @param {String} message Message to output.
    • @param {...Any} optionalParams Additional optional parameters.
  • warn Logs warning message to console if level is greater than 1.

    • @param {String} message Message to output.
    • @param {...Any} optionalParams Additional optional parameters.
  • error Logs error message to console if level is greater than 1.

    • @param {String} message Message to output.
    • @param {...Any} optionalParams Additional optional parameters.
  • trace Logs trace to console.

    • @param {String} message Message to output.
    • @param {...Any} optionalParams Additional optional parameters.

set.js

setByDotNotation

Set a value on a target by a dot seperated path.

  • @param {Object} target Target object to set value to.
  • @param {String} path Dot notation string with each segment a property on the target.
  • @param {Any} value The value to set at the path on the target.
  • @returns {Object} Target object with the value set to it.

setByPathSegments

Set a value on a target by an array seperated path.

  • @param {Object} target Target object to set value to.
  • @param {Array<String>} path Array of strings with each segment a property on the target.
  • @param {Any} value The value to set at the path on the target.
  • @returns {Object} Target object with the value set to it.

trim.js

trimStart

Trim a specific character from the start of a string.

  • @param {String} string String to trim.
  • @param {String} character Character to trim.
  • @returns {String} Trimmed string.

trim

Trim a specific character from the start and end of a string.

  • @param {String} string String to trim.
  • @param {String} character Character to trim.
  • @returns {String} Trimmed string.

trimEnd

Trim a specific character from the end of a string.

  • @param {String} string String to trim.
  • @param {String} character Character to trim.
  • @returns {String} Trimmed string.