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

ts-scribe

v0.4.0

Published

A collection of utility functions and types for TypeScript projects in Node.js

Downloads

230

Readme

TS-Scribe

npm

A TypeScript library tailored for Node.js development. It offers utility functions and custom types to enhance productivity and improve code quality. Whether you’re handling files, working with asynchronous operations, or ensuring type safety, ts-scribe provides valuable tools for your TypeScript projects.

Installation

npm install ts-scribe

Functions

Core

  • run: Helper to run a function or block of code in a cleaner way.
  • parseBoolean: Parses different kinds of values into a boolean.
  • parseNumber: Parses different kinds of values into a number.

Array

  • chunkArray: Splits an array into chunks of a specified size.
  • differenceArray: Returns the difference between two arrays.
  • groupBy: Groups an array of objects by a specified key.
  • intersection: Returns the intersection of two arrays.
  • pluckArray: Extracts a list of property values from an array of objects.
  • powerset: Returns the powerset of an array.
  • shuffleArray: Shuffle an array.
  • toArray: Converts almost anything into an array.
  • uniqueBy: Returns an array of unique objects based on a specified key.

Async

  • asyncForEach: Asynchronous for each function running in parallel (behaving like Promise.all).
  • debounced: Debounces a promise.
  • maybe: A Maybe monad is an immutable wrapper which allows you to defer handling of null/undefined values and errors until you want to capture the result of an operation. It's an alternative to frequent nullish checks and try/catch blocks.
  • retry: Retries a promise a specified number of times.
  • semaphore: Limits the number of promises that can be executed concurrently.
  • sleep: Pause the process for a certain amount of time.
  • waterfall: Runs an array of functions in series, each passing their results to the next in the array.

List

  • WeightedList: A list where each element has a weight associated with it. The probability of an element being selected is proportional to its weight.
  • SortedList: A list that maintains its elements in sorted order. It's useful for maintaining a list of elements that need to be sorted frequently.

Math

  • clamp: Clamps a number between a minimum and maximum value.
  • greatestCommonDivisor: Compute the greatest common divisor between any amount of numbers.
  • smallestCommonMultiple: Compute the smallest common multiple between any amount of numbers.

Object

  • deepClone: Deep clones an object. It's a faster and more accurate alternative to JSON.parse(JSON.stringify(obj)).
  • deepEquals: Deeply compares two objects or arrays.
  • deepFreeze: Deeply freeze an object.
  • deepMerge: Deep merges multiple objects and gives accurate types.
  • safeJsonParse: Parse a Json string safely.

Random

  • randomString: Generates a random string. You can specify the length and character set.
  • randomInt: Generates a random integer. You can specify the minimum and maximum values.
  • randomBool: Generates a random boolean. You can specify the probability of getting true.
  • randomSample: Returns random elements from an array. You can specify the number of elements to return.

String

  • toCamelCase: Converts a string to camelCase.
  • toKebabCase: Converts a string to kebab-case.
  • toSnakeCase: Converts a string to snake_case.
  • toDotCase: Converts a string to dot.case.
  • toPascalCase: Converts a string to PascalCase.
  • toHeaderCase: Converts a string to Header Case.

System

  • isBrowser: Checks if the code is run in a browser.
  • isNode: Checks if the code is run in NodeJS.

Typeguards

  • isDefined: Checks if a value is defined and not null / undefined / NaN.
  • isEmptyObject: Checks if an object is empty.
  • isNumber: Checks if any value is a number or can be parsed into a number.
  • isString: Checks if any value is a string.

Types

  • Primitive: JS primitive types.
  • Nullish: Only allows assignment of anything nullish.
  • NonNullish: Allows assignment of anything except nullish values.
  • Mandatory: Exclude nullish values from a type.
  • Nestable: A type that can be nested infinitely. Used in deepEquals and arrIntersection functions.
  • GenericFunction: A generic function type, useful for defining functions that accept any number of arguments and return any type. It's a stronger type than Function.
  • TypeOfString: Strings which can be used with typeof operator.
  • TypeOfType: Infer the typeof type from a typeof string.
  • UnionToIntersection: Convert a union type (|) to an intersection type (&).
  • SmartPartial: The keys that allow undefined are optional, the rest are required.
  • Simplify: If two or more types are intersected, it simplifies them into a single type for better readability.
  • OverloadUnion: Converts a union of functions into a single function with overloads.
  • ReadonlyDeep: Typescripts readonly but for nested objects.

Credits

License

MIT