Skip to content

Latest commit

 

History

History
353 lines (217 loc) · 5.89 KB

documentation.md

File metadata and controls

353 lines (217 loc) · 5.89 KB

JSTD Documentation

0. General funcs

0.1 typeis

Determine the type of a value

0.2 re

Regexp test function

re(regxp: RegExp, val: any): boolean

1. Array

1.1 arrayable

To determine a var is an array or not empty array

arrayable(array: any, length = true): boolean

1.2 arrayUnique

Retrieve unique elemens from an array

arrayUnique<T>(array: any, nested = false): Array<T>

1.3 arrValsCount

Retrieve elements exists count from an array

arrValsCount<T>(array: any): NumberDict

1.4 arrValCount

To Count the number of occurrences of an element in the array

arrValCount<T>(array: any, key: T): number

1.5 flat

Flatten an array recursively up to the specified depth.

flat<T>(array: any, depth = Infinity): OptionalPropertyArray<T> 

2. Buffer

2.1 url2Blob

Convert a string url to blob

url2Blob(url: string): Blob | never

2.2 str2Buffer

convert a string to buffer

str2Buffer(str: string): Uint8Array | undefined

2.3 buffer2Str

convert a buffer to a string

buffer2Str(buff: Uint8Array): string | undefined

2.4 _btoa/_atob

polyfill for window.btoa/window.atob

3. Date

3.1 formatDate

Date format

formatDate(date?: Date | string, format = 'yyyy-MM-dd hh:mm:ss'): string

3.2 timezoneDate

Retrieve a date with specify timezone

timezoneDate(year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, timezone?: string): Date | undefined

3.3 dateable

To determine a var is Date type

dateable(date?: any, validDate = true): boolean

3.4 quarterable

Retrieve a quarter string with another quarter and delta quarters which are used to calculate

quarterable(quarter: any, delta = 0, separator = 'Q'): string | undefined

4. Enum

4.1 inEnum

To determine whether a key in an Enum

inEnum<T>(enums?: Dict<T>, i?: string | T): boolean

4.2 Types

enum of Types

4.3 TypesDesc

enum of type's descriptions

5. eventloop

5.1 sleep

sleep in eventloop for milliseconds

sleep(ms = 16): Promise<number>

6. Map

6.1 mappable

To determine a var is an map or not empty map

mappable(map?: any, length = true): boolean

7. Math

7.1 rangeRandom

Retrieve a random number with range limit

rangeRandom(min?: any, max?: any): number

7.2 numberic

Formatting or rounding a value with digits limitation and rounding places limitation

numberic(val?: any, digits = 2, places?: number): number | undefined

7.3 guid

Generate a guid string randomly

guid(length = 8, salt = 'abcdefghijklmnopqrstuvwxyz0123456789'): string

7.4 hash

Generate a hash string randomly

hash(): string

7.5 numberFormat

Formatting or rounding a value with digits limitation and rounding places limitation

numberFormat(val?: any, digits = 2, places?: number): string | undefined

7.6 moneyFormat

Formatting a numberic like value into a string such as '1,000,000'

moneyFormat(val?: any, digits = 2, places?: number, defaultVal = ''): string

7.7 signFormat

Formatting with a positive/negative sign for a numberic value to a string such as '+1' or '-1', '0'

signFormat(val?: any, defaultVal = ''): string

8. Object

8.1 objectable

To determine a var is an Object type which is type of {}

objectable(obj: any, length = true): boolean

8.2 optional

Retrieve value from optional chain in an Object

optional<T>(path: any, obj?: any, separator = '.'): OptionalPropertyItem<T>

8.3 extractable

Extract some key-values from an object with some properties or custom key-value objects

extractable(...args: Array<ExtractableArgs>): Dict<any>

8.4 assign

Assign a value to an object with key path

assign<T>(path: any, obj: OptionalDict<T>, val?: any, separator = '.'): OptionalDict<T>

8.5 objReverse

Reverse an object's key and value

objReverse(obj?: OptionalDict<any> | null): OptionalDict<any> | null

9. Regexp

9.1 isNil

Determine whether a value is null/undefined/empty string

isNil(val?: any): boolean

9.2 isNull

Determine whether a value is equal to null

isNul(val?: any): boolean

9.3 isUndefined

Determine whether a value is equal to undefined

isUndefined(val?: any): boolean

9.4 isNumberic

Determine whether a value is numberic which support pure number-like and pure instance of Number

isNumberic(val: any, signed?: boolean, arabic = true): boolean | number

10. Set

10.1 settable

To determine a var is an set or not empty set

settable(set?: any, length = true): boolean

11. String

11.1 stringable

To determine a var is string or not empty string

stringable(str: any, length = true): boolean

11.2 strLen

To count the number of characters in a string

strLen(str: any): number

12. Function

12.1 copy

Create a copy of a variable deeply or not

copy(obj: any, deep = true): any

12.2 debounce

Debounce frequency for function execution

debounce<F extends Func>(fn: F, time: number | string, immediate = false): Func | never

12.3 throuttle

Throttle frequency for function execution

throuttle<F extends Func>(fn: F, time: number | string, options?: ThrottleOptions): Func | never

12.4 sort

Sort function for sorting array of numberic or not numberic values

sort(a: any, b: any, ignoreCase = false, locale = 'zh-Hans-CN')