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

1.0.0 • Public • Published

StringMethods

Few methods for working with strings

Install

npm install @lexriver/string-methods

Import

import {StringMethods} from '@lexriver/string-methods'
import {StringMethods, LocaleSettings} from '@lexriver/string-methods'

Methods

StringMethods.isDigits(x:string):boolean

Checks if string contains only digits: 0123456790

StringMethods.isDigits('345') // true

StringMethods.isValidEmail(x:any):boolean

Simple check if string contains some text before @ and at least one dot and text after dot after @

StringMethods.isValidEmail('test@me.pls') // true

StringMethods.getSimpleHash(value:string):number

Get simple fast hash of a string https://stackoverflow.com/questions/6122571/simple-non-secure-hash-function-for-javascript

StringMethods.getSimpleHash('test') === StringMethods.getSimpleHash('test') // true
StringMethods.getSimpleHash('test') === StringMethods.getSimpleHash('tset') // false

StringMethods.formatPluralNumber(p)

Get a nice string for plural number.

Arguments

    StringMethods.formatPluralNumber(p:{
        number: number,
         settings: { // StringMethods.LocaleSettings type
            locale?:string, 
            ifZero:(x:number)=>any, 
            ifOne:(x:number)=>any,
            ifFew:(x:number)=>any,
            ifMany:(x:number)=>any
        }
    }

Example

    let settings:StringMethods.LocaleSettings = {
        locale:'ru',
        ifZero:(x) => `товары не найдены`,
        ifOne:(x) => `${x} товар`,
        ifFew:(x) => `${x} товара`,
        ifMany:(x) => `${x} товаров`
   }

   StringMethods.formatPluralNumber({ number: 33, settings })) // 33 товара

Package Sidebar

Install

npm i @lexriver/string-methods

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

21.3 kB

Total Files

13

Last publish

Collaborators

  • lexriver