Skip to content

Latest commit

 

History

History
114 lines (72 loc) · 2.52 KB

StringExtensions.String.md

File metadata and controls

114 lines (72 loc) · 2.52 KB

js-stdlib-extensions / Exports / StringExtensions / String

Interface: String

StringExtensions.String

String

Table of contents

Methods

Methods

format

format(...args): string

Returns a formatted string using printf-like tokens, %s, for string substitution.

Parameters

Name Type Description
...args any[] Any amount of arguments to substitute for the same amount of %s in the originating string.

Returns

string

Example

// returns 'Hello world, today is Monday.'
'Hello %s, today is %s.'.format('world', 'Monday')

Defined in

string.ts:21


isEmpty

isEmpty(): boolean

Returns true if the length of the string is 0.

Returns

boolean

Example

// returns true
''.isEmpty()

Defined in

string.ts:30


toObject

toObject(options?): Object

Returns a one-dimensional (1-D) object from a (multi-line) template literal string that uses a separator, =, to distinguish key from value, while using new lines to separate key-value pairs. A callback function can also be provided to transform the keys and/or values before they are returned.

Parameters

Name Type Description
options? Object -
options.callbackFn? (value: [k: string, v: any]) => [k: string, v: any] If provided, the function will be used to transform the key-value pairs before output.
options.separator? string (Default: '=') If provided, the character(s) will be used to demarcate key-value pairs on a single line.

Returns

Object

Example

// returns { name: 'Jack', age: 42, single: false }
`name=Jack
age=42
single=false`.toObject()

Example

// returns { name: 'Mary', age: 25, single: true }
`NAME Mary
AGE 25
SINGLE true`.toObject({separator: ' ', callbackFn: ([k, v]) => [k.toLowerCase(), v]})

Defined in

string.ts:57