Global

Methods

assign(obj, key, value) → {object|array}

assign a property's value by its keyPath

Parameters:
Name Type Description
obj object | array
key KeyPath
value any
Returns:
Type
object | array

async_(fn, expireopt) → {function}

Create a function which return a Promise and cached by parameters.

Parameters:
Name Type Attributes Description
fn function

a function, can be async function or normal function

expire number <optional>

the expire time for releasing cache

Returns:

.clear() is available

Type
function
Example
const fn = async_(async () => {})

const a = fn()
const b = fn()

a === b // the same Promise

calculate(exp, decimalopt) → {string}

Parameters:
Name Type Attributes Description
exp string
decimal number <optional>
Source:
Returns:
Type
string

caseby(entries)

get value by different conditions

Parameters:
Name Type Description
entries Array.<function(), function()>

[[condition, getter]]

Source:

clearNum00(input) → {string}

Parameters:
Name Type Description
input number | string
Source:
Returns:
Type
string

clone(obj) → {T}

Parameters:
Name Type Description
obj T
Source:
Returns:
Type
T

compareby(a, b) → {number}

Parameters:
Name Type Description
a number | string
b number | string
Source:
Returns:
Type
number

compArray(a, b) → {Array.<any>}

Parameters:
Name Type Description
a Array.<any>
b Array.<any>
Source:
Returns:
Type
Array.<any>

compute_(fn, expireopt) → {function}

Create a function which cache result by parameters.

Parameters:
Name Type Attributes Description
fn function

the original function to calculate result

expire number <optional>

the time to expire cache, if set 0 (or not set), the cache will never be expired, default 0.

Source:
Returns:

you can call a .clear() method on this function to clear the cache

Type
function
Example
const compute = compute_((x, y) => {
  return x + y
})

// the following two computing will call original fn only once
const a = compute(1, 3)
const b = compute(1, 3)

compute.clear() // clear all cache

createArray(value, countopt) → {Array.<T>}

Parameters:
Name Type Attributes Description
value T
count number <optional>
Source:
Returns:
Type
Array.<T>

createDate(datetime, givenFormatteropt) → {Date}

Parameters:
Name Type Attributes Description
datetime Date | string | number
givenFormatter string <optional>
Source:
Returns:
Type
Date

createProxy(origin, options) → {any}

create a proxy object. it will change your original data

Parameters:
Name Type Description
origin object | array
options object
Properties
Name Type Description
get function

to modify output value of each node, receive (keyPath, proxiedValue), proxiedValue is a reactive object/array as if, keyPath is an array which catains keys in path

set function

to modify input value of each node, receive (keyPath, nextValue), nextValue is the given passed value, the return value will be transformed to be reactive object/array as if

dispatch function

to notify change with keyPath, receive (keypath, next, prev), it will be called after value is set into

writable function

whether be able to change value, return false to disable writable, default is true

Source:
Returns:
Type
any
Example
const some = {
  body: {
    hand: true,
    foot: true,
  },
}
const a = createProxy(some, {
  get(keyPath, value) {
    if (keyPath.join('.') === 'body.hand') {
      return value.toString()
    }
    else {
      return value
    }
  },
  set(keyPath, value) {},
  dispatch(keyPath, next, current) {},
})

a !== some // proxy object !== object
a.body !== some.body // proxy object !== object
a.body.hand !== some.body.hand // true !== 'true'
a.body.foot == some.body.foot // true == true

a.body.hand = false // now a.body.hand is 'false', a string
some.body.hand === false // some.body.hand changes to false

createRandomString(len, charSetopt) → {string}

Parameters:
Name Type Attributes Description
len number
charSet 10 | 36 | 62 <optional>

10: 0-9, 36: 0-9a-z, 62: 0-9a-zA-Z. default is 62

Source:
Returns:
Type
string

createReactive(origin, options) → {object|array}

create a reactive object. it will change your original data

Parameters:
Name Type Description
origin object | array
options object
Properties
Name Type Description
get function

to modify output value of each node, receive (keyPath, reactiveValue), reactiveValue is a reactive object/array as if, keyPath is an array which catains keys in path

set function

to modify input value of each node, receive (keyPath, nextValue), nextValue is the given passed value, the return value will be transformed to be reactive object/array as if

dispatch function

to notify change with keyPath, receive (keypath, next, prev), it will be called after value is set into

writable function

whether be able to change value, return false to disable writable, default is true

disable function

return true to disable create nest reactive on this node

Source:
Returns:
Type
object | array
Example
const some = {
  body: {
    hand: true,
    foot: true,
  },
}
const a = createReactive(some, {
  get(keyPath, value) {
    if (keyPath.join('.') === 'body.hand') {
      return value.toString()
    }
    else {
      return value
    }
  },
  set(keyPath, value) {},
  dispatch({
    keyPath,
    value, // receive value
    input, // getter output
    next, // created reactive
    prev, // current reactive
  }, force) {},
})

a !== some // reactive object !== object
a.body !== some.body // reactive object !== object
a.body.hand !== some.body.hand // true !== 'true'
a.body.foot == some.body.foot // true == true

a.body.hand = false // now a.body.hand is 'false', a string
some.body.hand === false // original data changed

createSafeExp(exp) → {string}

Parameters:
Name Type Description
exp string
Source:
Returns:
Type
string

debounce(fn, wait, immediateopt) → {function}

创建防抖函数

Parameters:
Name Type Attributes Description
fn function
wait number
immediate boolean <optional>

是否立即执行函数

Source:
Returns:
Type
function

decideby(decide, …args)

get value by using a function

Parameters:
Name Type Attributes Description
decide function
args any <repeatable>
Source:

define(obj, key, descriptor) → {object}

Parameters:
Name Type Description
obj object
key string
descriptor object | function
Source:
Returns:
Type
object

diffArray(a, b) → {Array.<any>}

Parameters:
Name Type Description
a Array.<any>
b Array.<any>
Source:
Returns:
Type
Array.<any>

divideby(a, b, decimalopt) → {string}

Parameters:
Name Type Attributes Description
a number | string
b number | string
decimal number <optional>

decimal length

Source:
Returns:
Type
string

each(obj, fn, descriptoropt) → {object|array}

Parameters:
Name Type Attributes Description
obj object | array
fn function
descriptor boolean <optional>
Source:
Returns:
Type
object | array

enumerify(input) → {string}

Parameters:
Name Type Description
input number | string
Source:
Returns:
Type
string

extend(obj1, obj2, mixArropt) → {object}

Deep extend an object

Parameters:
Name Type Attributes Description
obj1 object
obj2 object
mixArr 0 | 1 | 2 <optional>

0: extend array as object, 1: push into array, 2: replace all items

Source:
Returns:

obj1

Type
object

extract(obj, keys) → {object}

Parameters:
Name Type Description
obj object
keys Array.<string>
Deprecated:
  • use pick instead
Source:
Returns:
Type
object

filter(obj, fn) → {object}

Parameters:
Name Type Description
obj object | array
fn function
Source:
Returns:
Type
object

find(obj, fn) → {string}

在对象中查找,fn返回true表示找到,返回false表示没有找到继续找,找到后返回该属性的key,通过key就可以方便的获取value

Parameters:
Name Type Description
obj object | array
fn function
Source:
Returns:

返回key,找不到返回undefined

Type
string

fixNum(input, decimalopt, padopt, flooropt) → {string}

Parameters:
Name Type Attributes Description
input number | string
decimal number <optional>
pad boolean <optional>
floor boolean <optional>
Source:
Returns:
Type
string

flat(obj, determineopt) → {object}

Parameters:
Name Type Attributes Description
obj object | array
determine function <optional>
Source:
Returns:
Type
object

flatArray(arr) → {Array.<any>}

Parameters:
Name Type Description
arr Array.<Array.<any>>
Source:
Returns:
Type
Array.<any>

formatDate(datetime, formatter, givenFormatteropt) → {string}

Parameters:
Name Type Attributes Description
datetime Date | string | number
formatter string
givenFormatter string <optional>
Source:
Returns:
Type
string

formatNum(input, separator, count, formatdecimalopt) → {string}

Parameters:
Name Type Attributes Description
input number | string
separator string
count number
formatdecimal boolean <optional>
Source:
Returns:
Type
string

formatNum1000(input, formatdecimalopt) → {string}

Parameters:
Name Type Attributes Description
input number | string
formatdecimal boolean <optional>
Source:
Returns:
Type
string

formatString(input, separator, segments, alignrightopt) → {string}

Parameters:
Name Type Attributes Description
input string
separator string
segments array
alignright boolean <optional>
Source:
Returns:
Type
string

freeze(o) → {object}

deep freeze

Parameters:
Name Type Description
o object
Source:
Returns:
Type
object

fromEntries(entries, kv) → {object}

conver an entry/key-value array to an object

Parameters:
Name Type Description
entries Array.<array> | Array.<object>
kv boolean
Source:
Returns:
Type
object

get_(fn, typeopt) → {function}

create a getter function which will cache the result, cache will be released automaticly

Parameters:
Name Type Attributes Description
fn function

the getter function, notice, without parameters

type number <optional>

the type of automatic releasing, default 1.

  • 0: never released
  • 1: in Promise microtask
  • 2: in timeout task
  • 3: in requestAnimationFrame
  • 4: in requestIdleCallback
Returns:

you can call .clear() to clear cache immediately

Type
function
Example
const get = get_(() => {
  return Math.random()
})

// the following two getting will call original fn only once
const a = get()
const b = get()
a === b

// type: 1
const getter = get_(() => Date.now(), 1)
const e = getter()
Promise.then(() => {
  const h = getter()
  e !== h // cache is released in a previous Promise microtask
})
setTimeout(() => {
  const f = getter()
  e !== f // when type is 1, the cache will be release in a Promise microtask, so when we call setTimeout, cache is gone
})

// type: 2
const use = get_(() => Date.now(), 2)
const m = use()
Promise.then(() => {
  const n = use()
  m === n // when type is 2, the cache will be release in a setTimeout task, so when we call in a Promise.then, cache is existing
})
setTimeout(() => {
  const l = use()
  m !== l // cache was released in a previous setTimeout task
})

getConstructorOf(ins) → {any}

Parameters:
Name Type Description
ins any
Source:
Returns:
Type
any

getObjectHash(obj) → {number}

Parameters:
Name Type Description
obj object
Source:
Returns:
Type
number

getStringHash(str) → {number}

Parameters:
Name Type Description
str string
Source:
Returns:
Type
number

getSymbolContent(symb) → {string}

get the string of a symbol

Parameters:
Name Type Description
symb symbol
Source:
Returns:
Type
string

groupArray(arr, count) → {Array.<array>}

slice an array into [count] sub-array

Parameters:
Name Type Description
arr Array.<any>
count number
Source:
Returns:
Type
Array.<array>

hasOwnKey(obj, key, enumerableopt) → {boolean}

check wether a property is the given object's own property, as default, it will check:

  • both string and symbol properties (different from inObject),
  • both enumerable and non-enumerable properties;
Parameters:
Name Type Attributes Description
obj object | array
key string
enumerable boolean <optional>
Source:
Returns:
Type
boolean

inArray(item, arr) → {boolean}

Parameters:
Name Type Description
item any
arr array
Source:
Returns:
Type
boolean

inherit(Parent, proptotypes, statics) → {any}

Create a new Child any which is inherited from Parent any

Parameters:
Name Type Description
Parent any
proptotypes object
statics object
Source:
Returns:
Type
any

inObject(key, obj, ownopt) → {boolean}

check wether a property is the given object's own property, it will check:

  • only string properties (except symbol properties, different from hasOwnKey),
  • only enumerable properties;
Parameters:
Name Type Attributes Description
key string
obj object
own boolean <optional>

use hasOwnKey to check

Source:
Returns:
Type
boolean

interArray(a, b) → {Array.<any>}

Parameters:
Name Type Description
a Array.<any>
b Array.<any>
Source:
Returns:
Type
Array.<any>

interpolate(template, data, optsopt) → {string}

Parameters:
Name Type Attributes Description
template string
data object
opts object <optional>
Source:
Returns:
Type
string

invoke_(fn, countopt, expireopt) → {function}

create a function whose result will be cached, and the cache will be released by invoke count

Parameters:
Name Type Attributes Description
fn function
count number <optional>
expire number <optional>

the expire time after latest invoke

Returns:

.clear() is avaliable

Type
function
Example
const invoke = invoke_(() => {
  return Math.random()
}, 2)

const a = invoke()
const b = invoke()
const c = invoke()

a === b
a !== c

isAllInArray(items, arr) → {boolean}

is all items in array arr

Parameters:
Name Type Description
items Array.<any>
arr Array.<any>
Source:
Returns:
Type
boolean

isArray(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isArrayInArray(shortArr, longArr) → {boolean}

all items in shortArr are in longArr may be the same with isAllInArray

Parameters:
Name Type Description
shortArr *
longArr *
Source:
Returns:
Type
boolean

isBlob(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isBoolean(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isConstructor(f, strictopt) → {boolean}

judge whether a value is a Constructor

Parameters:
Name Type Attributes Description
f any
strict number <optional>

strict level

  • 4: should must be one of native code, native class
  • 3: can be babel transformed class
  • 2: can be some function whose prototype has more than one properties
  • 1: can be some function which has this inside
  • 0: can be some function which has prototype
Source:
Returns:
Type
boolean

isDate(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isEmpty(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isEqual(val1, val2) → {boolean}

Parameters:
Name Type Description
val1 any
val2 any
Source:
Returns:
Type
boolean

isFalsy(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isFile(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isFinite(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isFormData(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isFunction(value, isStrictopt) → {boolean}

Parameters:
Name Type Attributes Description
value any
isStrict boolean <optional>

where Constructor is to return false

Source:
Returns:
Type
boolean

isGt(a, b) → {boolean}

Parameters:
Name Type Description
a any
b any
Source:
Returns:
Type
boolean

isGte(a, b) → {boolean}

Parameters:
Name Type Description
a any
b any
Source:
Returns:
Type
boolean

isInfinite(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isInheritedOf(SubConstructor, Constructor, isStrictopt) → {boolean}

Parameters:
Name Type Attributes Description
SubConstructor any
Constructor any
isStrict boolean <optional>
Source:
Returns:
Type
boolean

isInstanceOf(value, Constructor, isStrictopt) → {boolean}

Parameters:
Name Type Attributes Description
value any
Constructor any
isStrict boolean <optional>
Source:
Returns:
Type
boolean

isLt(a, b) → {boolean}

Parameters:
Name Type Description
a any
b any
Source:
Returns:
Type
boolean

isLte(a, b) → {boolean}

Parameters:
Name Type Description
a any
b any
Source:
Returns:
Type
boolean

isNaN(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isNone(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isNull(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isNullish(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isNumber(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isNumeric(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isObject(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isOneInArray(items, arr) → {boolean}

is one of items in array arr

Parameters:
Name Type Description
items Array.<any>
arr Array.<any>
Source:
Returns:
Type
boolean

isPromise(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isProxy(value) → {boolean}

determine whether an object is a Proxy

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isShallowEqual(objA, objB, deepthopt) → {boolean}

Parameters:
Name Type Attributes Description
objA object
objB object
deepth number <optional>

how many deepth to check

Source:
Returns:
Type
boolean

isString(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isSymbol(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isTruthy(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

isUndefined(value) → {boolean}

Parameters:
Name Type Description
value any
Source:
Returns:
Type
boolean

iterate(obj, fn)

Parameters:
Name Type Description
obj object | array
fn function
Source:

joinArray(arr, join) → {Array.<any>}

Parameters:
Name Type Description
arr Array.<Array.<any>>
join any
Source:
Returns:
Type
Array.<any>

keyin(key, obj, enumerableopt) → {boolean}

check whether a keyPath is in the given object, both string and symbol properties will be checked, as default, it will check:

  • both enumerable and non-enumerable properties;
  • both own and prototype-chain properties; if enumerable=true, it will check:
  • only enumerable properties;
  • only own properties;
Parameters:
Name Type Attributes Description
key KeyPath
obj *
enumerable * <optional>
Returns:
Type
boolean

makeKey(keyPath) → {string}

convert a keyPath array or string to be a keyPath string

Parameters:
Name Type Description
keyPath KeyPath
Source:
Returns:
Type
string

makeKeyChain(path, isStrictopt) → {array}

convert a keyPath string to be an array

Parameters:
Name Type Attributes Description
path string
isStrict boolean <optional>

whether to keep square bracket keys

Source:
Returns:
Type
array

makeKeyPath(chain, isStrictopt) → {string}

convert an array to be a keyPath string

Parameters:
Name Type Attributes Description
chain array

the array for path, without any symbol in it

isStrict boolean <optional>

wether to use [] to wrap number key

Source:
Returns:
Type
string

map(obj, fn) → {object}

Parameters:
Name Type Description
obj object | array
fn function
Source:
Returns:
Type
object

matchAll(regexp, str) → {array}

Parameters:
Name Type Description
regexp RegExp
str string
Source:
Returns:
Type
array

merge(obj1, obj2, mixArropt) → {object}

Parameters:
Name Type Attributes Description
obj1 object
obj2 object
mixArr 0 | 1 | 2 <optional>

0: extend array as object, 1: push into array, 2: replace all items

Source:
Returns:

a new object

Type
object

minusby(a, b) → {string}

Parameters:
Name Type Description
a number | string
b number | string
Source:
Returns:
Type
string

mixin(Source, Extend)

mix Extend into Source, (notice: will override Source)

Parameters:
Name Type Description
Source any
Extend any
any
Source:

multiplyby(a, b) → {string}

Parameters:
Name Type Description
a number | string
b number | string
Source:
Returns:
Type
string

num10To(num, base) → {string}

convert base10 number to string

Parameters:
Name Type Description
num number
base number
Source:
Returns:
Type
string

num10to36(num) → {string}

Parameters:
Name Type Description
num number | string
Source:
Returns:
Type
string

num10to62(num) → {string}

Parameters:
Name Type Description
num number | string
Source:
Returns:
Type
string

num36to10(code) → {number}

Parameters:
Name Type Description
code string
Source:
Returns:
Type
number

num62to10(code) → {number}

Parameters:
Name Type Description
code string
Source:
Returns:
Type
number

numerify(num) → {string}

Parameters:
Name Type Description
num number | string
Source:
Returns:
Type
string

numTo10(code, base) → {number}

convert string to base10 number

Parameters:
Name Type Description
code string
base number
Source:
Returns:
Type
number

padLeft(str, len, pad) → {string}

Parameters:
Name Type Description
str string
len number
pad string
Source:
Returns:
Type
string

padRight(str, len, pad) → {string}

Parameters:
Name Type Description
str string
len number
pad string
Source:
Returns:
Type
string

parse(obj, key)

parse a property's value by its keyPath

Parameters:
Name Type Description
obj object | array
key KeyPath
Source:

parseAs(obj, key)

parse a property into a new object which contains only the parsed property

Parameters:
Name Type Description
obj object | array
key KeyPath
Example
var a = { a: 1, b: 2, c: 3 };
var b = parseAs(a, 'b'); // -> { b: 2 }

pick(obj, keys) → {object}

Parameters:
Name Type Description
obj object
keys Array.<string>
Source:
Returns:
Type
object

pipe_(…fns) → {function}

Parameters:
Name Type Attributes Description
fns function <repeatable>
Returns:
Type
function
Example
const pipe = pipe_(
  x => x + 1,
  x => x - 1,
  x => x * x,
  x => x / x,
)

const y = pipe(10) // 10

plusby(a, b) → {string}

Parameters:
Name Type Description
a number | string
b number | string
Source:
Returns:
Type
string

refineProxy(obj) → {any}

refine the original value from a Proxy

Parameters:
Name Type Description
obj object
Source:
Returns:
Type
any

remove(obj, key) → {object|array}

remove a property by its keyPath

Parameters:
Name Type Description
obj object | array
key KeyPath
Returns:
Type
object | array
Parameters:
Name Type Description
obj object | array
fn function
Source:
Returns:
Type
any

sortArray(items, byopt, decsopt) → {Array.<any>}

Parameters:
Name Type Attributes Description
items Array.<any>
by string <optional>

which property sort by

decs boolean <optional>
Source:
Returns:
Type
Array.<any>

splitArray(arr, splitter) → {Array.<array>}

split an array to sevral

Parameters:
Name Type Description
arr Array.<any>
splitter * | function
Source:
Returns:
Type
Array.<array>

stringify(obj) → {string}

Parameters:
Name Type Description
obj object
Source:
Returns:
Type
string

throttle(fn, wait, immediateopt) → {function}

创建节流函数

Parameters:
Name Type Attributes Description
fn function
wait number
immediate boolean <optional>

是否立即执行

Source:
Returns:
Type
function

toArray(arr) → {Array.<any>}

Parameters:
Name Type Description
arr any
Source:
Returns:
Type
Array.<any>

toEntries(obj) → {Array.<array>}

convert an object to an entry array

Parameters:
Name Type Description
obj object
Source:
Returns:
Type
Array.<array>

unionArray(a, b) → {Array.<any>}

Parameters:
Name Type Description
a Array.<any>
b Array.<any>
Source:
Returns:
Type
Array.<any>

uniqueArray(arr, propopt) → {Array.<any>}

Parameters:
Name Type Attributes Description
arr Array.<any>
prop string <optional>

unique by which property

Source:
Returns:
Type
Array.<any>

Type Definitions

KeyPath

Type:
  • string | number | Array.<(string|symbol|number)>
Source: