Skip to content

πŸ’ͺ Very strongly typed string functions in TypeScript

License

Notifications You must be signed in to change notification settings

dilan-dio4/strz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

strz – Very Strongly Typed String Functions

  • 0️⃣ No dependencies
  • 🌲 Tree shakable
  • πŸ“¦ Small
  • 5️⃣ Typescript 5
  • πŸ“ Strongly typed

Why?

In projects that encourage strong typing, the standard library requires manually casting to match function parameter signatures. strz brings the power of strong typing to the standard library.

Example

import { split, suffix } from 'strz'

const str = "The quick brown fox jumps over the lazy dog"

const splitStr = split(str, " ") // splitStr is of type ["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"]
const suffixed = suffix(str, "!") // suffixed is of type "The quick brown fox jumps over the lazy dog!"

Installation

npm install strz

Usage

import {
  charAt,
  toLowerCase,
  toUpperCase,
  toArray,
  slice,
  uncapitalize,
  capitalize,
  prefix,
  suffix,
  split,
  trim,
  trimStart,
  trimEnd,
  replaceAll,
  replace,
  length,
} from 'strz'

const str = "The quick brown fox jumps over the lazy dog"

// Before
const char = str.charAt(0) // char is of type string
// After
const char = charAt(str, 0) // char is of type "T"

// Before
const replaced = str.replaceAll(" ", "_" ) // replaced is of type string
// After
const replaced = replaceAll(str, " ", "_" ) // replaced is of type "The_quick_brown_fox_jumps_over_the_lazy_dog"

// And so on...

API

  • charAt βœ…
  • toLowerCase βœ…
  • toUpperCase βœ…
  • toArray βœ…
  • slice βœ…
    • This is a partial implementation of slice and does not support negative indices
  • uncapitalize βœ…
  • capitalize βœ…
  • prefix βœ…
  • suffix βœ…
  • split βœ…
  • trim βœ…
  • trimStart βœ…
  • trimEnd βœ…
  • replaceAll βœ…
    • This is a partial implementation of replaceAll and does not support regex
  • replace βœ…
    • This is a partial implementation of replace and does not support regex
  • length βœ…

About

πŸ’ͺ Very strongly typed string functions in TypeScript

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published