A small JavaScript utility library.
Package with rollup.js
, exported as iife amd cmd cjs umd es6
module.
Support most modern browsers, not include IE
. Support Node 8+.
框架搭建教程:打造一个类似于lodash的现代前端工具库
npm install @zollty/zollty-util
examples:
validate:
isBankCard,
isIdCard,
isPhoneNum,
validateMobile,
collection:
toMapKey,
toMapValue,
string:
strTemplate,
import {
toMapKey,
toMapValue
} from '@zollty/zollty-util';
console.log(toMapKey); // Function
console.log(toMapValue); // Function
Can also import like
import zt from '@zollty/zollty-util';
console.log(zt.toMapKey); // Function
console.log(zt.toMapValue); // Function
or like this
import toMapKey from '@zollty/zollty-util/toMapKey';
import toMapValue from '@zollty/zollty-util/toMapValue';
console.log(toMapKey); // Function
console.log(toMapValue); // Function
get the key set of a map and a value array:
// suppose have data
const data = {"s":5, "a": 4, "b": 3, "c": 2, "d": 1}
const vals = [4 ,3, 2]
// we want to get the key set ["a", "b", "c"]
const keys = zt.toMapKey(vals, data);
get the value set of a map and a key array:
// suppose have data
const data = {"s":5, "a": 4, "b": 3, "c": 2, "d": 1}
const keys = ["a", "b", "c"]
// we want to get the value set [4, 3, 2]
const vals = zt.toMapValue(keys, data);
/**
* 替换模块字符串中的占位符
* ,例如s = <span id="aaa">{{a}}</span>
* val = {a:111}
* 结果为:<span id="aaa">111</span>
* 如果,
* val = [{a:111}, {a:222}]
* split = <br/>
* 结果为:
* <span id="aaa">111</span><br/><span id="aaa">222</span>
*
* @param {string} s 模板字符串,例如<span>{{b}}</span>
* @param {Object|array} val 值
* @param {string} split 数组分割字符
*/
function strTemplate(s, val, split)
please see the code directly.
Released under the MIT Licenses.