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

@semantic-ui/utils

v0.1.5

Published

**Utils is a tiny 3kb library for simplifying common javascript boilerplate.**

Downloads

411

Readme

@semantic-ui/utils

Utils is a tiny 3kb library for simplifying common javascript boilerplate.

Utils has three primary advantages over custom implementations.

  • Tree Shaking - Many components will need to do similar things. When these components are bundled together its more efficient for them to reference a single code implementation than several unique ones. This means smaller bundled size when using more than one component together in a bundle.

  • Code Readability - Utility libraries offer a level of familiarity and consistency that can be missing with native ECMAScript features. Removing rough edges reduces the learning curve when looking at unfamiliar code so you can focus on the intention not the implementation.

  • Gotcha Handling - More Robust Implementations: When using utility libraries for common operations like object manipulation, you're not just avoiding gotchas (consider non-enumerated properties with object manipulation like extend/clone.); you're also leveraging a community-tested solution. These libraries often include safeguards against edge cases and peculiarities of JavaScript that a typical custom implementation might overlook. This results in more robust code, reducing the likelihood of bugs related to subtle language intricacies.

Utility includes the following helpers:

Arrays

  • unique(arr) - Removes duplicates from arrays.
  • filterEmpty(arr) - Removes falsey values from an array.
  • last(array, number) - Returns last (n) elements from array
  • first(array, number) - Returns first (n) elements from array
  • firstMatch(array, callback) - Returns the first value that matches the provided callback function.
  • findIndex(array, callback) - Finds the index of the first element in the array that satisfies the provided callback function. Returns -1 if no match is found.
  • remove(array, callbackOrValue) - Removes elements from an array that match the given callback function or value.
  • inArray(value, array) - Returns whether a value is present in an array.
  • range(start, stop, step) - Creates an array of numbers (positive and/or negative) progressing from start up to, but not including, end.
  • where(array, properties) - Returns only objs with given properties in an array of objects.
  • flatten(arr) - Flattens an array of arrays
  • some/any(arr, truthFunc) - Returns true if any/some values match truthFunc
  • sum(values) - sums an array of numbers

Numbers

  • roundNumber(number, digits) - rounds a number to a given number significant

DOM

  • `copyText(text) - Copies text to clipboard

Objects

  • keys(obj) - Return the keys of an object.
  • values(obj) - Return the values of an object.
  • mapObject(obj, callback) - Creates an object with the same keys as object and values generated by running each own enumerable string keyed property of object thru iteratee.
  • extend(obj, ...sources) - Extends an object with properties from additional sources, handling getters and setters properly.
  • pick(obj, ...keys) - Creates an object composed of the picked object properties.
  • get(obj, string) - Access a nested object field with a string, like 'a.b.c'.
  • onlyKeys(obj, keysToKeep) - Returns an object with only specified keys
  • hasProperty(obj, prop) - Return true if the object has the specified property.
  • reverseKeys(obj) - Reverses a lookup object's keys and values.
  • `arrayFromObject(obj) - Returns an array with key value pairs from an object

Types

  • isObject(x) - Checks if the value is an object.
  • isPlainObject(x) - Checks if the value is a plain object.
  • isString(x) - Checks if the value is a string.
  • `isBoolean(x) - Checks if the value is a boolean.
  • isNumber(x) - Checks if the value is a number.
  • isArray(x) - Checks if the value is an array.
  • isBinary(x) - Checks if the value is binary (Uint8Array).
  • isFunction(x) - Checks if the value is a function.
  • isPromise(x) - Checks if the value is a promise.
  • isArguments(obj) - Checks if the value is an arguments object.
  • isDOM(x) - Checks if the value is a DOM element.
  • isNode(x) - Checks if the value is a DOM node.
  • isEmpty(x) Checks if the value is empty like {}
  • isClassInstance(x) - Checks if the value is an instance of a custom class

Date

  • formatDate(date, format) - Formats a date object into a string based on the provided format.

Functions

  • noop() - A no-operation function for use as a default callback.
  • wrapFunction(x) - Wraps a value in a function, returning a no-op function if the value is not a function.

Strings

  • kebabToCamel(str) - Converts a kebab-case string to camelCase.
  • camelToKebab(str) - Converts a camelCase string to kebab-case.
  • capitalize(str) - Capitalize only the first word in a string.
  • capitalizeWords(str) - Capitalizes each word of a string
  • toTitleCase(str) - Converts a string to title case.

Regular Expressions

  • escapeRegExp(string) - Escapes special characters in a string for use in a regular expression.
  • escapeHTML(string) - Escapes string for html '&<>"' only

Looping

  • each(iterable, func, context) - Calls function for each element of an iterable.
  • `asyncEach(iterable, func, context) - Calls iteratee awaiting each function
  • `asyncMap(iterable, func, context) - Calls each func awaiting the mapped result

Equality

  • isEqual(a, b) - Deep compares two values to determine if they are equivalent.

Cloning

  • clone(a) - Performant clone of Array, Object, Date, regExp, Map, Set, or other data.

Identity

  • tokenize(str) - Returns a tokenized version of a string
  • prettifyID(num) - Converts a numeric ID into a more human-readable string format.
  • hashCode(input) - Creates a hash code from a string, object, or array (murmur hash)
  • generateID() - Generates a pseudo-random unique identifier.

Errors

  • fatal(message, options) - Throws a custom error asynchronously, allowing for metadata and stack trace modifications.

Constants

  • isServer - Boolean whether code is running on server
  • isClient - Boolean whether code is running on client