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

@syncify/utils

v0.0.1

Published

Common utility box for a better development experience.

Downloads

62

Readme

@syncify/utils

Utilties box designed to simplify common development tasks. Though part of the Syncify project, this package can also function independently. Provides a collection of helper functions to enhance your development workflow and alleviate extranous code operations.

Installation

pnpm add @syncify/utils

Usage

Functions within this package are organized by their operational focus, aiding in various data manipulations, string operations, array handling, and asynchronous tasks.

String Manipulation

import * as u from '@syncify/utils'

// Join a string together with no space
u.glue('foo', 'bar') => 'foobar'

// Join a string together with a single space character
u.glueString('foo', 'bar') => 'foo bar'

// Join string array or spread strings with newline characters
u.glueLines('foo', 'bar') => 'foo\nbar\n'

// Generate a random string UUID
u.uuid() => 'a1b2c3'

// Converts string input to a handle by replacing non-alphanumeric characters with hyphens
u.handleize('hello world') => 'hello-world'

// Adds an 's' to the end of a word if size is not 1
u.plural('example', 1) => 'examples'

// Capitalize the first letter of a string
u.toUpcase('example') => 'Example'

// Append an `st`, `nd`, `rd` or `th` to the end of a number
u.addSuffix(10) => '10th'

Type Checks

import * as u from '@syncify/utils'

// Check whether value is `undefined` or `null`
u.isNil(null) => true

// Check whether value is an even number
u.isEven(1) => false

// Check whether a Buffer or String is empty after trimming
u.isEmptyString('') => true

// Check whether an object or array is empty
u.isEmpty('') => true

// Check if param is an array type
u.isArray([]) => true

// Check if param is an object type
u.isObject({}) => true

// Check if param is a non-empty string type
u.isStringStrict('x') => true

// Check if param is a string type
u.isString('') => true

// Check if param is a date type
u.isDate(Date) => true

// Check if param is a regular expression type
u.isRegex(/[a-z]/) => true

// Check if param is a function type
u.isFunction(() => {}) => true

// Check if param is a boolean type
u.isBoolean('true') => false

// Check if param is a constructor or function prototype
u.isConstructor(class X {}) => true

// Check if param is a number type, hexadecimal, or math-like string
u.isNumberStrict(0x) => true

// Check if param is a number type
u.isNumber(1) => true

// Check if param is `NaN`
u.isNaN(NaN) => true

// Check if param is null type
u.isNull(null) => true

// Check if param is undefined type
u.isUndefined(undefined) => true

// Check if param is an Asynchronous function
u.isAsync(async () => {}) => true

// Check if param is a Buffer type
u.isBuffer(Buffer) => true

Object Structures

import * as u from '@syncify/utils'

//  Check if a deeply nested path exists in an object
u.hasPath("a.b", { a: { b: 'value' } }) => true

// Check if a property exists directly in an object
u.has('name', { name: 'John', age: 30 }) => true

// Return a function to check if a property exists in an object for currying
u.hasProp({ name: 'John', age: 30 })('name') => true

Promise / Event Loop

import * as u from '@syncify/utils'

// Returns a promise that resolves in the next event loop
u.pNext() => Promise

// Runs provided tasks in series, handling both async and sync tasks
u.pSerial([ async () => {} ]) => Promise

// Creates a debounced function for promise-returned functions with error handling
u.debouncePromise(() => Promise, 1, onError: (e) => {}) => (v) => void

Miscellaneous

import * as u from '@syncify/utils'

// Creates an object with null prototype, optionally accepts object param
u.object() => {}

// An immutable merge utility for objects with deep support
u.merge({ a: 'x' }, { b: 1 }) => { a: 'x', b: 1 }

// Returns an MD5 hash from string or buffer
u.checksum('foo') => 'a1b2c3d4e6f8g9a1b2c3d4e6f8g9'

Contributing

This package is designed for usage within Syncify. Contributions are not accepted unless they pertain to the core Syncify module. If contributions fall into that category, fork the Syncify project.