@vulppi/string
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Vulppi String

A simple string library.

Usage

For regular expressions, you can use the following:

import { REGEXP_UUID, REGEXP_EMAIL } from '@vulppi/string'

console.log(REGEXP_UUID.test('123e4567-e89b-12d3-a456-426614174000')) // true
console.log(REGEXP_EMAIL.test('john.due@example.com')) // true

For string manipulation, you can use the following:

import { createInjector } from '@vulppi/string'

const injector = createInjector(
  // The filters for manipulate data
  {
    uppercase: (value: string) => value.toUpperCase(),
    lowercase: (value: string) => value.toLowerCase(),
    capitalize: (value: string) =>
      value.charAt(0).toUpperCase() + value.slice(1).toLowerCase(),
    date: (value: string) =>
      new Intl.DateTimeFormat('en-US').format(new Date(value)),
  },
)

console.log(injector('Hello world. {name@capitalize}!', { name: 'MARIE' }))
// Output: `Hello world. Marie!`

console.log(injector('Now is {now@date}', { now: new Date() }))
// Output: `Now is 1/1/2021`

Package Sidebar

Install

npm i @vulppi/string

Weekly Downloads

47

Version

0.0.2

License

MIT

Unpacked Size

11.7 kB

Total Files

7

Last publish

Collaborators

  • morbden