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-multitool

v0.0.5

Published

TypeScript MultiTool - A library full of tree-shakable TypeScript functions for application construction in both CommonJS and ESM

Downloads

4

Readme

TypeScript MultiTool 🛠

On the journey of building applications in TypeScript you will need a menagerie of functions. Typically the user's trip down Google lane will bring you to StackOverflow. The code is copied into the editor and the app construction continues. Bad, no chance the testing is added and now problems arise. The TypeScript MultiTool is a tree-shakable pile of functions helpful for building apps with all of the tests included in the library.

Motivation

Building software accurately and quickly tends to yield solutions which are simply missing test coverage for quick and dirty functions plucked from google searches or StackOverflow. This library is my own collection of functions I am using with the included test coverages to manage them.

Furthering, in my experience, I find great solutions and I'll adopt them in a project. Months down the road I'll research the same problem and will stop and realize in the middle of the research "I have looked for this before" and I'll search my own solutions for it. I have done a poor job denoting great known-good solutions. This is an attempt to encapsulate the runtime from time spent researching.

Installation

The recommended way to install is through npm or Yarn. The library is exposed as CommonJS and ESM.

npm:

npm install ts-multitool

yarn:

yarn add ts-multitool

Usage

The entire point of ts-multitool is simplicity with the goal of producing rapid test-able solutions in TypeScript

Functions

Text Functions (available at /text/)


commaSeparatedString(string[],useOxfordComma)

Take a list of strings and create a comma separated string. The useOxfordComma will place an Oxford Comma

import { commaSeparatedString } from 'ts-multitool'
const response = commaSeparatedString(['first', 'second', 'third'])
assert(response === 'first, second and third')

capitalize(string)

Capitalizes the first letter of a string. It does NOT force lowercase on the remaining letters.

import { capitalize } from 'ts-multitool'
const response = capitalize('thomas')
assert(response === 'Thomas')

truncate(string,length,useWordBoundary,ellipsis)

Truncates the string at the given length and adds an ellipsis. The useWordBoundary will truncate at the nearest word boundary. The ellipsis will be added to the end of the string.

import { truncate } from 'ts-multitool'
const line1 = truncate('The quick brown fox jumps over the lazy dog', 20, true, '...')
const line2 = truncate('The quick brown fox jumps over the lazy dog', 20)
assert(line1 === 'The quick brown fox...')
assert(line2 === 'The quick brown fox…')

Array Functions (available at /array/)


unique<T>(T[])

Returns a list of unique values from the given array (supports primitives)

import { unique } from 'ts-multitool'
const list = unique([1, 2, 3, 4, 3, 2, 4, 1])
// returns [1, 2, 3, 4]

uniqueValue(value:string, list:string[]): string

Determines and possibly mutates value to ensure it is unique in the list of values

import { uniqueValue } from 'ts-multitool'
const field1 = uniqueValue('a', ['a', 'b', 'c'])
// returns 'a0'
const field2 = uniqueValue('a', ['a', 'a0', 'a1'])
// returns 'a2'

File Functions (available at /files/)


getExtension(string)

Get the extension of a file.

import { getExtension } from 'ts-multitool'
const ext = getExtension('somefile.that.you.need.jpg')
assert(response === 'jpg')

Have something to add (or something is busted)?

Something to add to the library? Cool, add it and create a PR! If there is something busted in the library? Whoops, file an issue!

Tests

Tests are executed via Jest.

npm run test