Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 товара

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages