JSPM

@marcelkloubert/strings

1.3.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q15748F
  • License MIT

String helpers for Node and the browser.

Package Exports

  • @marcelkloubert/strings
  • @marcelkloubert/strings/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@marcelkloubert/strings) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

npm last build PRs Welcome

@marcelkloubert/strings

String helpers, for Node.js 14+ and the browser.

Install

Execute the following command from your project folder, where your package.json file is stored:

npm i @marcelkloubert/strings

Usage

asString(value: any): string

import { asString } from "@marcelkloubert/strings"

const myObject = {
  toString: () => "!!!myObject!!!",
}

asString(12)  // "12"
asString("")  // ""
asString(null)  // ""
asString(undefined)  // ""
asString(myObject)  // "!!!myObject!!!"

format(formatStr: string. ...args: any[]): string

import { format } from "@marcelkloubert/strings"

format("{1}, {0}", "Marcel", "Kloubert")  // "Kloubert, Marcel"
format("{1:lower,trim}, {0:upper}", "Marcel", "  kloubert  ")  // "kloubert, MARCEL"
format("{1}, {0} Joachim", null, undefined)  // "{1},  Joachim"

formatArray(formatStr: string, args: List): string

import { formatArray } from "@marcelkloubert/strings"

function* asGenerator(...args: any[]) {
  for (const a of args) {
    yield a
  }
}

formatArray("{1}, {0}", ["Marcel", "Kloubert"])  // "Kloubert, Marcel"
formatArray("{1:lower,trim}, {0:upper}", asGenerator("Marcel", "  kloubert  "))  // "kloubert, MARCEL"
formatArray("{1}, {0} Joachim", [null, undefined])  // "{1},  Joachim"

StringBuilder

import { StringBuilder } from "@marcelkloubert/strings"

const str = new StringBuilder("Bar") // "Bar"
  .append("Foo") // "FooBar"
  .prependFormat("{1}, {0:upper,trim} ", "  Marcel  ", "Klbert") // "Klbert, MARCEL FooBar"
  .replace("MARCEL", "Tanja") // "Klbert, Tanja FooBar"
  .insert(2, "ou") // "Kloubert, Tanja FooBar"
  .clear() // ""

str.isEmpty // (true)
str.equals("") // (true)
str.equals(null) // (true)
str.equals(undefined) // (true)

Documentation

The API documentation can be found here.

License

MIT © Marcel Joachim Kloubert

Support and contribute

PayPal donate button Patreon donate button Buy Me A Coffee donate button

Contribution guidelines