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

@twodashes/universal

v0.5.8

Published

Universal utility functions for both browser and node (like @lodash, but with more dashes). Mostly "pure" functions (sorting ones use [].sort()). Promises, filtering, sorting, combining, text analysis, math, curry, sleep, etc. See also platform specific f

Downloads

4

Readme

Universal "kitchen sink" utility functions

Like @lodash, but with more dashes (lots of functionality, and uses underscores instead of camelCase). Utilities and "pure" functions (almost pure - sorting use [].sort()). Promises, filtering, sorting, combining, text analysis, math, curry, sleep, etc.

See also: 📙🚀 @twodashes/browser 📙🚀, which is structured the same way, but only for browser-specific code like OS, Retina, AJAX, URLs, etc. Also @twodashes/node, for HTTP requests and CLI args for Node. Planned for the future are more platform-specific functions: "@twodashes/rnative" for React Native, "@twodashes/ionic", and in a galaxy far far away "@twodashes/quasar".

⚠️ PLEASE NOTE: ⚠️

All names in this library (functions, files) will change. Currently figuring out what to call everything. This library will be stabled when released as version 1. All this is new and NOT well tested. Please let me know if anything is broken.

npm package testing in progress Currently in progress: testing, documentation, examples.

Try it:

Use it instantly in CodeSandbox.io

Installation

ES Modules - import from "/esm/" to support tree-shaking:

  import { sort_by_rating_and_position } from "@twodashes/universal/esm/sort_strings"

CommonJS - require from "/umd/" folder:

  const { sort_by_rating_and_position } = require("@twodashes/universal/umd/sort_strings")

Browser script tag use "/umd/" folder

<!-- download all functions into window.__ -->
<script src="https://cdn.jsdelivr.net/npm/@twodashes/universal@latest/umd/index.js"></script>
<!-- download only the types of functions you need into window.__ - from /umd/category_of_functions -->
<script src="https://cdn.jsdelivr.net/npm/@twodashes/universal@latest/umd/sort_strings.js"></script>

This builds as UMD (Universal Module Definition) in the "/umd/" folder, for both Node.js and the browser. The original code is built using ES Modules, and is available in "/esm/" folder. It is not minified, but is small, simple, and efficient enough without being transpiled, so feel free to import from "/esm/".

Documentation

Lodash contents (for comparison and reference):

Twodash contents (documentation pages coming soon):

  • coming soon - for now please see "./src" folder which uses standard JsDoc comments

Other libraries to try (steal functions from):

Featured (examples):

Universal functions:

str_hash() to make a unique number out of a long or short string of text. Not for security or cryptography, but helps a lot to make a unique ID.

syllable_count() returns number of syllables for a given word

arr_remove_item() removes a value from an array, by value

ends_in_vowel() returns true if the input word ends in a vowel

sort_objects_by_property() just like sort_by_rating_and_position(), but instead of taking a list of items and object of ratings as separate parameters, it takes a list of objects, and sorts the list based on a property of each object.

sleep() returns a Promise after a number of milliseconds. Use with async/await to mimic other programming languages like Bash

for_each_promise_all() returns a Promise - like a [].forEach, executes the function on each value in array - but with Promises

call_later() a taste of curry - define the function and arguments seprately, to be called later.

parse_error_message() Error messages come in all shapes and sizes. From simple string, to standard new Error('...') to Axios/fetch promises containing an error... Returns a string which you can display to your user, without fear.

For browser only:

load_script() loads a script file into your document

object_from_querystring() and other URL utils

is_retina() true if on MacBook for example, or any other "retina" or higher resolution screen

For node.js only:

parse_cli_args() gets arguments passed to NodeJS process when it was started

And many more

As I make write (or find on Stackoverflow) a new function for myself/clients/employers, I copy it to this library. Please contribute your own. Let's combine efforts!

See CodePen example. Play around with all the functions.

Develop:

Please try it, file an issue, add or fix some code, make a pull request. I'd love to make you an equal contributor. Contact Paul Shorey with any feature requests or bugs. Thank you! Unit tests, code sandbox examples, and better documentation are currently in progress.

This project is built using ES Modules in ./esm/. It is then compiled into Universal Module Definition (UMD) in ./umd/ which works in Node.js and the browser.