Skip to content

Latest commit

 

History

History
367 lines (224 loc) · 6.25 KB

string.md

File metadata and controls

367 lines (224 loc) · 6.25 KB

jaaJSU - v2.0.0 / $string

Namespace: $string

This NAMESPACE provides features for strings.

Version

2.0.0

Table of contents

Interfaces

Functions

Public

clearHTML

clearHTML(str): string

Clear tags from str

Parameters

Name Type
str string

Returns

string

Text without HTML tags


clearSpaces

clearSpaces(str): string

Clear spaces (\s+) in str

Deprecated

Use String.prototype.replace OR String.prototype.replaceAll

Parameters

Name Type
str string

Returns

string


concatLeft

concatLeft(text_right): (text_left: string) => string

Curried function for joining text: text_right=> text_left=> text_left+text_right

Parameters

Name Type
text_right string

Returns

fn

▸ (text_left): string

Parameters
Name Type
text_left string
Returns

string


concatRight

concatRight(text_left): (text_right: string) => string

Curried function for joining text: text_left=> text_right=> text_left+text_right

Parameters

Name Type
text_left string

Returns

fn

▸ (text_right): string

Parameters
Name Type
text_right string
Returns

string


containsRepeatingChars

containsRepeatingChars(str, quantity?): boolean

console.log($string.containsRepeatingChars("AAbcd"));//=false
console.log($string.containsRepeatingChars("AAAbcd"));//=true
console.log($string.containsRepeatingChars("AAAbcd", 3));//=false

Parameters

Name Type Description
str string -
quantity? number (By default 2)

Returns

boolean


containsSequential

containsSequential(str, quantity?): boolean

console.log($string.containsSequential("ABccc"));//=false
console.log($string.containsSequential("ABCdd"));//=true
console.log($string.containsSequential("ABCdd", 3));//=false

Parameters

Name Type Description
str string -
quantity? number (By default 2)

Returns

boolean


countChars

countChars(str): number

Number of chars in str

Parameters

Name Type
str string

Returns

number


escapeHTML

escapeHTML(str): string

Escapes "<", ">", "&", '"', "'"

Parameters

Name Type
str string

Returns

string


generateUnique

generateUnique(): string

An unique string

Returns

string


getSubstring

getSubstring(str, len, start?): string

Wrapper around *.substring(*,*)

Deprecated

Use String.prototype.split

Parameters

Name Type Description
str string -
len number How many chars
start? number (By default 0)

Returns

string

Substring of str


isFilled

isFilled(str): boolean

Wrapper around *.trim()

Parameters

Name Type
str string

Returns

boolean


letterInc

letterInc(str, inc?, pos?): string

New string with "highter" letter on position pos

console.log($string.letterInc("125"));//="126"
console.log($string.letterInc("125a"));//="125b"
console.log($string.letterInc("HH"));//="HI"
console.log($string.letterInc("Hg", 2, 1));//="Hi"

Parameters

Name Type Description
str string [a-zA-z] at least on position pos
inc? number (By default 1) inc=0 is convert to inc=1
pos? number (By default str.length-1)

Returns

string


template

template(str, keysFun?): TemplateString

Alternative to ```text with ${variable}``` (something like sprintf())

const test1= $string.template("${0}, ${1}, ${2}");
console.log(test1.partial(["A"]));//="A, ${1}, ${2}"
console.log(test1.execute(["B", "C", "D"]));//="A, C, D"
console.log(test1.isSubstituted());//=false
console.log(test1.partial(["_", "B", "C"]));//="A, B, C"
console.log(test1.isSubstituted());//=true

const test2= $string.template("${test0}, ${test1}, ${test2}");
console.log(test2.partial({test0: "A"}));//="A, ${test1}, ${test2}"
console.log(test2.execute({test0: "B", test1: "C", test2: "D"}));//="A, C, D"
console.log(test2.isSubstituted());//=false
console.log(test2.partial({test0: "_", test1: "B", test2: "C"}));//="A, B, C"
console.log(test2.isSubstituted());//=true

Parameters

Name Type Description
str string String in the form text…${key}….
keysFun? (o: Object) => PropertyKey[] If defined, used to filter keys in *.execute method.

Returns

TemplateString


toCamelCase

toCamelCase(str): string

Converts string to camel case format "peter"=>"Peter"

Parameters

Name Type
str string

Returns

string

Private

isEmail

isEmail(email_candidate): boolean

Parameters

Name Type
email_candidate string

Returns

boolean