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

rolling-ts-utils

v1.0.8

Published

A small library which exposes some helpful generic utility types

Downloads

7

Readme

Rolling TS Utils

A small library which exposes some helpful generic utility types. This is an early version and currently contains only a few types, but will be gradually expanded and improved.

Installation

npm install --save-dev rolling-ts-utils

Basic Usage

import type { ReplaceStringPart } from "rolling-ts-utils";

const str = "This is a cool {noun}." as const;

let sentence: ReplaceStringPart<typeof str, "dog">;
//  ^? typeof sentence = "This is a cool dog."

Available Types

ReplaceStringPart<OriginalString, NewString>

  • OriginalString: The string to be replaced
  • NewString: The string to replace the first occurrence of {string}, where string is any string
  • If no {string} is found, the original string is returned
const str = "This is a cool {noun}." as const;

let sentence: ReplaceStringPart<typeof str, "dog">;
//  ^? typeof sentence = "This is a cool dog."

ReplaceStringPart<OriginalString, NewString, Match>

  • OriginalString: The string to be replaced
  • NewString: The string to be inserted at the first occurance of Match
  • Match: The substring to be replaced
  • If no match is found, the original string is returned
const str = "This is a cool {noun}." as const;

let sentence: ReplaceStringPart<typeof str, "cat", "{noun}">;
//  ^? typeof sentence = "This is a cool cat."

ReplaceStringPartGlobal<OriginalString, NewString, Match>

  • OriginalString: The string to be replaced
  • NewString: The string to be inserted at each occurance of Match
  • Match: The substring to be replaced
  • If no match is found, the original string is returned
const str = "This is {word} {word} {thing}." as const;

let sentence: ReplaceStringPartGlobal<typeof str, "dog", "{word}">;
//  ^? typeof sentence = "This is dog dog {thing}."

ReplaceOrderedStringParts<OriginalString, NewStrings, Index>

  • OriginalString: The string to be replaced
  • NewStrings: An array of strings to be inserted in order
  • Index: The index of the substring to be replaced (this should normally be left empty)
  • If no {string} is found, the original string is returned

This will break if the NewStrings array contains more than 1000 elements

const str = "This is {article} {adjective} {noun}." as const;

let sentence: ReplaceOrderedStringParts<
  typeof str,
  ["an", "amazing", "rabbit"]
>;
//  ^? typeof sentence = "This is an amazing rabbit."

ReplaceMultipleStringParts<OriginalString, Keys, Values, Index>

  • OriginalString: The string to be replaced
  • Keys: An array of substrings to be replaced
  • Values: An array of strings to be inserted in place of the key at the same position in the Keys array
  • Index: The index of the substring to be replaced (this should normally be left empty)
  • If no match is found, the key-value pair has no impact

This will break if the Keys array contains more than 1000 elements

const str = "This is {article} {adjective} {noun}." as const;

let sentence: ReplaceMultipleStringParts<
  typeof str,
  ["{article}", "{adjective}", "{noun}"],
  ["an", "interesting", "duck"]
>;
//  ^? typeof sentence = "This is an interesting duck."

ReplaceAllStringParts<OriginalString, NewString>

  • OriginalString: The string to be replaced
  • NewString: The string to be inserted in place of ALL occurrences of {string}, where string is any string
const str = "This is {article} {adjective} {noun}." as const;

let sentence: ReplaceAllStringParts<typeof str, "dog">;
//  ^? typeof sentence = "This is dog dog dog."

Inc<OriginalNum>

  • OriginalNum: A number to be incremented

This will break if OriginalNum is greater than 999

type OriginalNum = 5;

type IncrementedNum = Inc<OriginalNum>;
//   ^? type IncrementedNum = 6