amos-tool
Version:
amos ui tool
841 lines (730 loc) • 28.9 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>Home - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
<script src="scripts/nav.js" defer></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav >
<input type="text" id="nav-search" placeholder="Search" />
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Logger.html">Logger</a><ul class='methods'><li data-type='method'><a href="Logger.html#pkgInfo">pkgInfo</a></li><li data-type='method'><a href="Logger.html#pkgWarn">pkgWarn</a></li></ul></li><li><a href="RayDB.html">RayDB</a></li></ul><h3>Global</h3><ul><li><a href="global.html#_boost">_boost</a></li><li><a href="global.html#_defaultBrowsers">_defaultBrowsers</a></li><li><a href="global.html#_muiltBrowsers">_muiltBrowsers</a></li><li><a href="global.html#advancePolicy">advancePolicy</a></li><li><a href="global.html#alphaHexMap">alphaHexMap</a></li><li><a href="global.html#amosCookie">amosCookie</a></li><li><a href="global.html#array2tree">array2tree</a></li><li><a href="global.html#arrayFilter">arrayFilter</a></li><li><a href="global.html#beautifyRoutes">beautifyRoutes</a></li><li><a href="global.html#browserSupport">browserSupport</a></li><li><a href="global.html#bt4ToHex">bt4ToHex</a></li><li><a href="global.html#byteToString">byteToString</a></li><li><a href="global.html#calcBrowserVersion">calcBrowserVersion</a></li><li><a href="global.html#checkFileName">checkFileName</a></li><li><a href="global.html#checkFlash">checkFlash</a></li><li><a href="global.html#clone">clone</a></li><li><a href="global.html#colorKeyWordsHexStr">colorKeyWordsHexStr</a></li><li><a href="global.html#completeUnit">completeUnit</a></li><li><a href="global.html#contains">contains</a></li><li><a href="global.html#customEqual">customEqual</a></li><li><a href="global.html#debounce">debounce</a></li><li><a href="global.html#deepCopy">deepCopy</a></li><li><a href="global.html#deepEqual">deepEqual</a></li><li><a href="global.html#DesUtils">DesUtils</a></li><li><a href="global.html#divide">divide</a></li><li><a href="global.html#drawPolygon">drawPolygon</a></li><li><a href="global.html#enc">enc</a></li><li><a href="global.html#encodeLen">encodeLen</a></li><li><a href="global.html#encodeNumber">encodeNumber</a></li><li><a href="global.html#eq">eq</a></li><li><a href="global.html#fieldContentRegExp">fieldContentRegExp</a></li><li><a href="global.html#fileSizeToByte">fileSizeToByte</a></li><li><a href="global.html#fileterAllMatchedData">fileterAllMatchedData</a></li><li><a href="global.html#filterAllCheckedData">filterAllCheckedData</a></li><li><a href="global.html#filterChilds">filterChilds</a></li><li><a href="global.html#filterTreeLevel">filterTreeLevel</a></li><li><a href="global.html#genBitmapImage">genBitmapImage</a></li><li><a href="global.html#generateKeys">generateKeys</a></li><li><a href="global.html#getFileExtension">getFileExtension</a></li><li><a href="global.html#getKeyBytes">getKeyBytes</a></li><li><a href="global.html#getTreeFlatKeys">getTreeFlatKeys</a></li><li><a href="global.html#gradientColor">gradientColor</a></li><li><a href="global.html#has">has</a></li><li><a href="global.html#hasOwnProp">hasOwnProp</a></li><li><a href="global.html#hasOwnProperty">hasOwnProperty</a></li><li><a href="global.html#hexToBt4">hexToBt4</a></li><li><a href="global.html#imageCompress">imageCompress</a></li><li><a href="global.html#isArray">isArray</a></li><li><a href="global.html#isBaseNaN">isBaseNaN</a></li><li><a href="global.html#isBlank">isBlank</a></li><li><a href="global.html#isBoolean">isBoolean</a></li><li><a href="global.html#isBuiltInObject">isBuiltInObject</a></li><li><a href="global.html#isCollection">isCollection</a></li><li><a href="global.html#isDom">isDom</a></li><li><a href="global.html#isElement">isElement</a></li><li><a href="global.html#isEmpty">isEmpty</a></li><li><a href="global.html#isEmptyObject">isEmptyObject</a></li><li><a href="global.html#isENumber">isENumber</a></li><li><a href="global.html#isFloat">isFloat</a></li><li><a href="global.html#isGIF">isGIF</a></li><li><a href="global.html#isHexColor">isHexColor</a></li><li><a href="global.html#isImageSrc">isImageSrc</a></li><li><a href="global.html#isInputEqual">isInputEqual</a></li><li><a href="global.html#isInteger">isInteger</a></li><li><a href="global.html#isJson">isJson</a></li><li><a href="global.html#isKeyColor">isKeyColor</a></li><li><a href="global.html#isKeyInObject">isKeyInObject</a></li><li><a href="global.html#isnan">isnan</a></li><li><a href="global.html#isNil">isNil</a></li><li><a href="global.html#isNull">isNull</a></li><li><a href="global.html#isNullOrUndefined">isNullOrUndefined</a></li><li><a href="global.html#isNumber">isNumber</a></li><li><a href="global.html#isObject">isObject</a></li><li><a href="global.html#isOnlyObject">isOnlyObject</a></li><li><a href="global.html#isOpacity">isOpacity</a></li><li><a href="global.html#isOwnKeyInObject">isOwnKeyInObject</a></li><li><a href="global.html#isPromise">isPromise</a></li><li><a href="global.html#isRegExp">isRegExp</a></li><li><a href="global.html#isRgbColor">isRgbColor</a></li><li><a href="global.html#isUndefined">isUndefined</a></li><li><a href="global.html#isUrl">isUrl</a></li><li><a href="global.html#isValidDate">isValidDate</a></li><li><a href="global.html#keyColorToHex">keyColorToHex</a></li><li><a href="global.html#Log">Log</a></li><li><a href="global.html#MAX_LENGTH">MAX_LENGTH</a></li><li><a href="global.html#merge">merge</a></li><li><a href="global.html#mergeAll">mergeAll</a></li><li><a href="global.html#mod">mod</a></li><li><a href="global.html#multiply">multiply</a></li><li><a href="global.html#normalPolicy">normalPolicy</a></li><li><a href="global.html#null2default">null2default</a></li><li><a href="global.html#objRGB2str">objRGB2str</a></li><li><a href="global.html#parse">parse</a></li><li><a href="global.html#pathToTree">pathToTree</a></li><li><a href="global.html#plus">plus</a></li><li><a href="global.html#PNGlib">PNGlib</a></li><li><a href="global.html#Queue">Queue</a></li><li><a href="global.html#random">random</a></li><li><a href="global.html#randomInt">randomInt</a></li><li><a href="global.html#ranks">ranks</a></li><li><a href="global.html#recursive">recursive</a></li><li><a href="global.html#recursiveGen">recursiveGen</a></li><li><a href="global.html#rgb2object">rgb2object</a></li><li><a href="global.html#saveAsImage">saveAsImage</a></li><li><a href="global.html#serialize">serialize</a></li><li><a href="global.html#shallowEqual">shallowEqual</a></li><li><a href="global.html#simpleEqual">simpleEqual</a></li><li><a href="global.html#simpleThrottle">simpleThrottle</a></li><li><a href="global.html#slpitArray">slpitArray</a></li><li><a href="global.html#some">some</a></li><li><a href="global.html#stringIsJson">stringIsJson</a></li><li><a href="global.html#strToBt">strToBt</a></li><li><a href="global.html#subObjectEqual">subObjectEqual</a></li><li><a href="global.html#subtract">subtract</a></li><li><a href="global.html#throttle">throttle</a></li><li><a href="global.html#toHexAlphaColor">toHexAlphaColor</a></li><li><a href="global.html#toHexColor">toHexColor</a></li><li><a href="global.html#toRealSize">toRealSize</a></li><li><a href="global.html#toRGBcolor">toRGBcolor</a></li><li><a href="global.html#toStringHexColor">toStringHexColor</a></li><li><a href="global.html#transformColor">transformColor</a></li><li><a href="global.html#useMd5Policy">useMd5Policy</a></li><li><a href="global.html#useMd5Policy2">useMd5Policy2</a></li><li><a href="global.html#utils">utils</a></li><li><a href="global.html#values">values</a></li></ul>
</nav>
<div id="main">
<section class="package">
<h3> </h3>
</section>
<section class="readme usertext">
<article><h1>amos-tool</h1>
<p>by ilex.h</p>
<p>docs: <a href="https://unpkg.com/amos-tool@latest/docs/index.html">docs</a></p>
<h2>useage</h2>
<p>npm install --save amos-tool</p>
<h2>keywords</h2>
<ul>
<li>amos ui</li>
<li>amos tool</li>
</ul>
<h2>infos</h2>
<p><a href="https://packagephobia.now.sh/result?p=amos-tool"><img src="https://packagephobia.now.sh/badge?p=amos-tool" alt="install size"></a></p>
<h2>api</h2>
<table>
<thead>
<tr>
<th>name</th>
<th>link</th>
<th>description</th>
</tr>
</thead>
<tbody>
<tr>
<td>Base64</td>
<td><a href="#base64">Base64</a></td>
<td><code>base64加密解密</code></td>
</tr>
<tr>
<td>MD5</td>
<td><a href="#md5">MD5</a></td>
<td><code>md5加密解密</code></td>
</tr>
<tr>
<td>DES</td>
<td><a href="#des">DES</a></td>
<td><code>des加密解密</code></td>
</tr>
<tr>
<td>Browser</td>
<td><a href="#browser">Browser</a></td>
<td><code>获取浏览器类型</code></td>
</tr>
<tr>
<td>deepCopy</td>
<td><a href="#deepCopy">deepCopy</a></td>
<td><code>深度复制</code></td>
</tr>
<tr>
<td>deepEqual</td>
<td><a href="#deepEqual">deepEqual</a></td>
<td><code>深度比较(stringify方式)</code></td>
</tr>
<tr>
<td>fastDeepEqual</td>
<td><a href="#fastDeepEqual">fastDeepEqual</a></td>
<td><code>深度比较(循环)</code></td>
</tr>
<tr>
<td>parseText</td>
<td><a href="#parseText">parseText</a></td>
<td><code>替换或者补全url</code></td>
</tr>
<tr>
<td>List</td>
<td><a href="#list">List</a></td>
<td><code>List集合</code></td>
</tr>
<tr>
<td>Queue</td>
<td><a href="#queue">Queue</a></td>
<td><code>队列</code></td>
</tr>
<tr>
<td>UUID</td>
<td><a href="#uuid">UUID</a></td>
<td><code>uuid</code></td>
</tr>
<tr>
<td>browserSupport</td>
<td><a href="#browserSupport">browserSupport</a></td>
<td><code>浏览器支持</code></td>
</tr>
<tr>
<td>Log</td>
<td><a href="#log">Log</a></td>
<td><code>定制化的log日志</code></td>
</tr>
<tr>
<td>Store</td>
<td><a href="#store">Store</a></td>
<td><code>数据处理,主要是localStorage、session、cookie</code></td>
</tr>
<tr>
<td>LocationParam</td>
<td><a href="#locationParam">LocationParam</a></td>
<td><code>location 工具</code></td>
</tr>
<tr>
<td>array2tree</td>
<td><a href="#array2tree">array2tree</a></td>
<td><code>将array转化为tree数据</code></td>
</tr>
<tr>
<td>tableFilter</td>
<td><a href="#tableFilter">tableFilter</a></td>
<td><code>表格数据过滤</code></td>
</tr>
<tr>
<td>pwdPolicy</td>
<td><a href="#pwdPolicy">pwdPolicy</a></td>
<td><code>密码生成器</code></td>
</tr>
<tr>
<td>omit</td>
<td><a href="#omit">omit</a></td>
<td><code>omit操作,删除object中的键</code></td>
</tr>
<tr>
<td>pick</td>
<td><a href="#pick">pick</a></td>
<td><code>pick操作,获取object指定key组成的新对象</code></td>
</tr>
<tr>
<td>utils</td>
<td><a href="#utils">utils</a></td>
<td><code>常用工具</code></td>
</tr>
<tr>
<td>xss</td>
<td><a href="#xss">utils</a></td>
<td><code>xss 工具及</code></td>
</tr>
<tr>
<td>strUtils</td>
<td><a href="#strUtils">strUtils</a></td>
<td><code>string常用工具</code></td>
</tr>
<tr>
<td>other</td>
<td><a href="#other">other</a></td>
<td><code>其它工具集</code></td>
</tr>
</tbody>
</table>
<h3>base64</h3>
<pre class="prettyprint source lang-js"><code>import { Base64 } from 'amos-tool';
// or import Base64 from 'amos-tool/lib/encrypt/_base64';
var b64 = new Base64();
b64.encode(input);
b64.decode(input);
</code></pre>
<h3>md5</h3>
<pre class="prettyprint source lang-js"><code>import { MD5 } from 'amos-tool';
// or import MD5 from 'amos-tool/lib/encrypt/_md5';
var result = MD5('value'); // 2063c1608d6e0baf80249c42e2be5804
var result = MD5('value', 'key'); // 01433efd5f16327ea4b31144572c67f6
var result = MD5('value', null, true); // 'c\xc1`\x8dn\x0b\xaf\x80$\x9cB\xe2\xbeX\x04'
var result = MD5('value', 'key', true); // '\x01C>\xfd_\x162~\xa4\xb3\x11DW,g\xf6'
</code></pre>
<h3>des</h3>
<blockquote>
<p>注意,加密解密时,第一个 <code>秘钥</code> 不能为空</p>
</blockquote>
<pre class="prettyprint source lang-js"><code>DES.DesCore.encode(data, firstKey, secondKey, thirdKey)
DES.DesCore.decode(data, firstKey, secondKey, thirdKey)
DES.encode(data, secretKey);
DES.decode(data, secretKey);
</code></pre>
<ul>
<li>example</li>
</ul>
<pre class="prettyprint source lang-js"><code>import { DES } from 'amos-tool';
// or import DES from 'amos-tool/lib/encrypt/des';
const desCore = DES.DesCore;
desCore.encode('123456', 'a'); // 484FD6D18A5501370873DB5F557A23F9
desCore.encode('123456', 'a', 'b'); // 953AFFF48E49E4B94D8B74AABB6905E5
desCore.encode('123456', 'a', 'b', 'c'); // 7C49B05CCBCBEECC5665732A177E624B
desCore.decode('484FD6D18A5501370873DB5F557A23F9', 'a'); // 123456
desCore.decode('953AFFF48E49E4B94D8B74AABB6905E5', 'a', 'b'); // 123456
desCore.decode('7C49B05CCBCBEECC5665732A177E624B', 'a', 'b', 'c'); // 123456
DES.encode('123456', 'a'); // 484FD6D18A5501370873DB5F557A23F9
DES.encode('123456', 'a,b'); // 953AFFF48E49E4B94D8B74AABB6905E5
DES.encode('123456', 'a,b,c'); // 7C49B05CCBCBEECC5665732A177E624B
DES.decode('484FD6D18A5501370873DB5F557A23F9', 'a'); // 123456
DES.decode('953AFFF48E49E4B94D8B74AABB6905E5', 'a,b'); // 123456
DES.decode('7C49B05CCBCBEECC5665732A177E624B', 'a,b,c'); // 123456
</code></pre>
<blockquote>
<p>注意:</p>
</blockquote>
<p>secretKey 'a,b,c' 与 <code>a, b,c</code> 不同,识别空格。 支持3个秘钥,采用 <code>,</code> 分割</p>
<p>同时,<code>DES.DesCore</code> 第一个 key 值不可以为 空('', undefined, null)</p>
<h3>browser</h3>
<pre class="prettyprint source lang-js"><code> Browser.isFirefox();
Browser.isIE();
Browser.isEdge();
Browser.isChrome();
Browser.isSafari();
</code></pre>
<h3>deepCopy</h3>
<pre class="prettyprint source lang-js"><code>import { deepCopy } from 'amos-tool';
deepCopy(source);
import deepCopy, { eq } from 'amos-tool/lib/_deepCopy';
eq(value, other)
</code></pre>
<h3>deepEqual</h3>
<pre class="prettyprint source lang-js"><code>deepEqual(valA, valB);
</code></pre>
<h3>fastDeepEqual</h3>
<pre class="prettyprint source lang-js"><code>fastDeepEqual(valA, valB);
</code></pre>
<h3>parseText</h3>
<pre class="prettyprint source lang-js"><code>
/**
* 解析数据
* @param {string} text
* @param {object} dataObj
* @param {string|RegExp} regexps 可选
* @doc parseText('a/{b}/{c}/d',{a: 1, b:2}) 返回: 'a/1/2/d'
* @doc parseText('a/b?name={name}&pwd={pwd}',{name: 'ilex', pwd:122}) 返回: 'a/b?name=ilex&pwd=123'
*/
parseText(text, dataObj, regexps);
</code></pre>
<h3>list</h3>
<pre class="prettyprint source lang-js"><code> List props:
ArrayList: var arrlist = new List.ArrayList();
parse2string: List.parse2string(obj)
parse2object: List.parse2object(str)
simpleEqual: List.simpleEqual(objA, objB)
isObject: List.isObject(obj)
// ArrayList
var arrlist = new List.ArrayList();
arrlist.size(); // get size of list
arrlist.values();// all values
arrlist.isEmpty();// check empty
arrlist.iterator(callBack);// iterator
arrlist.get(index);// 取得指定下标的值
arrlist.add(value); // add item
arrlist.addAll(value);// add all item, value is a arrayList
arrlist.set(index, value);// 设置值
arrlist.remove(value);// remove item
arrlist.removeAt(index); // //remove item by index
arrlist.indexOf(value); // get item index from list
arrlist.clear(); // clear list
arrlist.insert(index, value); // insert item in index place
arrlist.updateValue(key, value); // use value[key] check equal
</code></pre>
<h3>queue</h3>
<pre class="prettyprint source lang-js"><code> var q = new Queue;
q.push(obj) // 入队
q.pop();// 出队
q.head();// 返回队列中头部(即最新添加的)的动态对象
q.tail();// 返回队列中尾部(即最早添加的)的动态对象
q.length();// 返回数据队列长度
q.empty(); // 队列是否为空
q.clear(); // 清空
</code></pre>
<h3>uuid</h3>
<pre class="prettyprint source lang-js"><code> uuid(len, radix); // radix must be <= 62 , uuid(8, 2)
uuidFast();
uuidCompact();
timeUUID(prefix = 'amos-timeuuid');
longTimeUUID(prefix = 'longtime');
otherUUID(tpl = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'); // 同 uuidCompact,无 '-'
</code></pre>
<h3>browserSupport</h3>
<ul>
<li>apis</li>
</ul>
<pre class="prettyprint source lang-js"><code> simpleuse:
defaultConfig: ['firefox/51.0', 'chrome/56']
browserSupport();
browserSupport('firefox/51.0');
browserSupport(['firefox/51.0', 'chrome/56']);
withMatchs:
muitlConfig: ['firefox/', 'chrome/'];
browserSupport(null, {
'firefox/': {limit: consts.GREATER_EQUAL, version: 51},
'chrome/': {limit: consts.GREATER_EQUAL, version: 56}
});
browserSupport('firefox/', {limit: consts.GREATER_EQUAL, version: 51});
browserSupport(['firefox/', 'chrome/'], {
'firefox/': {limit: consts.GREATER_EQUAL, version: 51},
'chrome/': {limit: consts.GREATER_EQUAL, version: 56}
});
consts:
GREATER: 1, // 大于
EQUAL: 2, // 等于
LESS: 3, // 小于
GREATER_EQUAL: 4, // 大于等于
LESS_EQUAL: 5 // 小于等于
</code></pre>
<ul>
<li>demo</li>
</ul>
<pre class="prettyprint source lang-js"><code>// 基本使用
const result = browserSupport();
const paramsList = ['firefox/', 'chrome/', 'ie'];
const limit = {
'firefox/': { limit: consts.GREATER_EQUAL, version: 50 },
'chrome/': { limit: consts.GREATER_EQUAL, version: 55 },
'ie': { limit: consts.GREATER_EQUAL, version: 6 }
};
// 自定义使用 (注意适配ie时 写法)
const result2 = browserSupport(paramsList, limit);
</code></pre>
<h3>log</h3>
<pre class="prettyprint source lang-js"><code>
window.LogConfig
window.LogConfig.isDebug
Log.trace()
Log.debug()
Log.info()
Log.warn()
Log.error()
Log.fatal()
// 展示 pkg 信息,不受 LogConfig 配置影响
Log.pkgInfo(name, version)
</code></pre>
<h3>store</h3>
<pre class="prettyprint source lang-js"><code>`default function list`
// 所有的cookie数据,均采用 escape/unescape 进行转码、解码
encrypt(str) // 加密
decrypt(str) // 解密
setCookieByDays(name, value, days)
getAllCookies() // 获取所有的cookie,同时每个key对应的value,均执行了 JSON.parse(value)
setCookieByHour(name, value, hour)
getCookieByName(name)
removeCookieByName(name)
clearAllCookie()
`localStorage`
const ls = Store.lsTool;
ls.read(key)
ls.write(key, data)
ls.each(fn)
ls.remove(key)
ls.clearAll()
`sessionStorage`
const session = Store.session;
session.read(key)
session.write(key, data)
session.each(fn)
session.remove(key)
session.clearAll()
</code></pre>
<h3>locationParam</h3>
<pre class="prettyprint source lang-js"><code> parse(paramString):
`if paramString is undefined, paramString=window.location.search`
`return all params Key Pair object`
paramSearch(name, target):
`if target is undefined, default window.location.search`
`and if name is undefined too `
`return keyValueObjec; else if name not empty return value;`
getLocationParams():
`get all locationParams, and return a key-value object`
getLocationParamByName(name):
`get param value by name, and return value or null`
getParameter(url, name):
`get target url Parameter by name, and return value or '' `
extractParam(url, name): `解析指定 url 中的参数,返回指定 name 的参数`
extractParams(url): `解析指定 url 中的参数,参数对象,如果 url 为undefined,则默认采用 window.location.href`
`LocationSearch` LocationParam.LocationSearch
`other search tool`
private: _keyValuePairs
public:
init():
`init this tool,set private property _keyValuePairs and return a LocationSearch`
getValue(key):
`return target value`
getParameters():
`return all param value`
</code></pre>
<h3>array2tree</h3>
<pre class="prettyprint source lang-js"><code>
import { array2tree } from 'amos-tool';
const data = [{
value: 'a',
children: [{
value: 'b',
children: [{
value: 'c'
}, {
value: 'd',
}]
}],
}];
const values = ['a', 'b', 'c'];
const result = array2tree(
data, (item, level) => item.value === values[level]
);
console.log(result);
// [
// { value: 'a', children: [...] },
// { value: 'b', children: [...] },
// { value: 'c', children: [...] }
// ]
</code></pre>
<h3>tableFilter</h3>
<pre class="prettyprint source lang-js"><code> getChildrenlength(children)
flatToHierarchy(arr)
filterParentPosition(arr)
isInclude(smallArray, bigArray)
/**
* 过滤数据
*
* @param {Array} vals 数据集合
* @param {any} treeData tree数据
* @returns
*/
filterAllCheckedData(vals, treeData)
/**
* 递归
*
* @param {any} children
* @param {any} cb
*/
recursive(children, cb)
</code></pre>
<h3>pwdPolicy</h3>
<pre class="prettyprint source lang-js"><code>
/**
* 普通密码生成策略
* @param {string} password
* @return {object} { password, secretKey }
*/
normalPolicy(password)
/**
* 普通密码生成策略
* @param {string} password 密码
* @param {string} secretKey 秘钥
* @return {object} { password, secretKey }
*/
advancePolicy(password, secretKey)
/**
* 采用MD5生成密码 (不可逆)
* @param {string} password
* @param {string} secretKey
*/
useMd5Policy(password, secretKey)
</code></pre>
<h3>omit</h3>
<pre class="prettyprint source lang-js"><code> const ilex = {name: 'ilex', age: 18};
const copy = omit(ilex, ['']); // {name: 'ilex', age: 18};
const copy = omit(ilex, ['age']); // {name: 'ilex'}
const copy = omit(ilex, ['name', 'age']); // {}
</code></pre>
<h3>pick</h3>
<pre class="prettyprint source lang-js"><code> const ilex = {name: 'ilex', age: 18};
const copy = pick(ilex, ['']); // {};
const copy = pick(ilex, ['age']); // {age: 18}
const copy = pick(ilex, ['name', 'age']); // {name: 'ilex', age: 18}
</code></pre>
<h3>utils</h3>
<pre class="prettyprint source lang-js"><code> isString(obj);
// Is a given value an array?
// Delegates to ECMA5's native Array.isArray
`If you want to judge object and judge array, you need to judge array first`
isArray(obj);
// Is a given variable an object?
isObject(obj);
// Is a given array, string, or object empty?
// An "empty" object has no enumerable own-properties.
isEmpty(objOrArray);
// Is a given value equal to null?
isNull(obj);
// Is a given variable undefined?
isUndefined(obj);
// Is json
isJson(obj);
// is image src,支持的格式(jpe?g|png|gif|bmp|ico|tga) 及其 base64 格式
isImageSrc(url);
/**
* 将数字部分内容转化为 *
* @param {Number} number 目标 Number
* @param {Number} start 起始位置
* @param {Number} len 转换位数
* @param {String} sign 替换的字符
*/
encodeNumber(number, start = 3, len = 4, sign = '*');
/**
* some
* some 为数组中的每一个元素执行一次 callback 函数,直到找到一个使得 callback 返回一个“真值”
* @param {Array} arr
* @param {function} fun
*/
some(arr, fun /*, thisArg */ );
//
every(arr, callbackfn, thisArg);
//
reduce(arr, callback /*, initialValue*/);
mergeAll(targetAndSources, overwrite);
merge(target, source, overwrite);
clone(source);
</code></pre>
<h3>xss</h3>
<pre class="prettyprint source lang-js"><code>import htmlEncode from 'amos-tool/lib/xss/htmlEncode';
import implementEncode from 'amos-tool/lib/xss/implementEncode';
htmlEncode('<'); // <
htmlEncode('>'); // >
htmlEncode('\''); // '
htmlEncode('\"'); // "
...
implementEncode('<script language=text/javascript>alert(document.cookie);</script>');
implementEncode('</script>');
implementEncode(' eval(abc);');
implementEncode('<img src="" onerror="alert(document.cookie);"></img>');
...
</code></pre>
<h3>strUtils</h3>
<pre class="prettyprint source lang-js"><code> toCapitalStr(obj);
// 驼峰化, 仅支持首字母大写、或者采用中杠连接的两个字母首字母大写
// 如果要支持其它输入,将正则改为: /(-|(\s+)|_)(\w)/g
camelCase(obj);
// 将中缸连接的字符串 驼峰化
transCamel(obj);
// 字符串首字母大写
capFirst(objOrArray);
// 获取字符串的hashCode码
hashCode(obj);
// 进制与单位处理
dealScaleAndUnit(obj);
</code></pre>
<h3>DB</h3>
<pre class="prettyprint source lang-js"><code>import { StorageDB, RayDB } from 'amos-tool';
// 使用 RayDB
const rdb = new RayDB('my-data');
rdb.setItem('key', 'value', successCb);
rdb.setItem('key', 'value').then(() => {}).catch(err => console.log(err));
rdb.getItem('key', (err, value) => {});
rdb.getItem('key').then(v => {}).catch(err => console.log(err));
// 使用 StorageDB, storeName 即为 key 值
const st = new StorageDB({ name: 'db-name', storeName: 'my-table' });
st.init(() => {
// 此处可以使用 st.get 获取初始数据
});
// 设置
st.set(value, evt => {
});
// 获取
st.get((value) => {
//
});
</code></pre>
<h3>other</h3>
<ul>
<li>
<p>cookie:</p>
</li>
<li>
<p>isNode
isNode();</p>
</li>
<li>
<p>objectAssign:</p>
<pre><code>objectAssign(target, source);
</code></pre>
</li>
<li>
<p>parseJson:</p>
<p>parseJson(data)</p>
</li>
<li>
<p>stringify:</p>
<p>stringify(json)</p>
</li>
<li>
<p>supportWs:</p>
<p>supportWs()</p>
</li>
<li>
<p>trim:</p>
<p>trim(str)</p>
</li>
<li>
<p>arrayFilter:</p>
</li>
<li>
<p>merged:</p>
<p>merged(args): combine object property</p>
</li>
<li>
<p>objectPath</p>
<p>@see <a href="doc/objectPath.md">doc/objectPath.md</a></p>
</li>
<li>
<p>random</p>
<p>random(len)
random.randomInt(min, max)</p>
</li>
</ul>
<h4>extra</h4>
<ul>
<li>pathToTree</li>
</ul>
<pre class="prettyprint source lang-js"><code>import pathToTree from 'amos-tool/lib/extra/pathToTree';
const arr = [
'main/lib',
'console/tt/design1',
'console/mm/vizlib'
];
const mapper = {
main: 'RootView',
console: 'ConsoleView'
};
var result1 = pathToTree(arr, {
pathKey: 'path',
childrenKey: 'childRoutes',
processor(item, wantedNode){
if (mapper[wantedNode]){
item.component = mapper[wantedNode];
}
}
});
</code></pre>
<h4>dom</h4>
<ul>
<li>canvas2img</li>
</ul>
<blockquote>
<p>saveAsImage(canvas/<em>canvasElement</em>/, width, height, type)
saveAsPNG(canvas, width, height)
saveAsGIF(canvas, width, height)
saveAsBMP(canvas, width, height)
convert2Image(canvas, width, height, type)
convert2data(canvas, type, width, height)
convert2Blob</p>
</blockquote>
<pre class="prettyprint source lang-js"><code>/**
* @param {Canvas} canvas
* @param {function} fn (blob) => {}
* @param {Object} options {
* type: '', // 图片类型 默认 'image/png',其它类型详见MIME手册
* width: number, // 宽
* height: number, // 高
* encoderOptions: 0-1 // 图片质量
* }
*/
convert2Blob(canvas, fn, options)
</code></pre>
<blockquote>
<p>convert2PNG(canvas, width, height)
convert2JPEG(canvas, width, height)
convert2GIF(canvas, width, height)
convert2BMP(canvas, width, height)</p>
</blockquote>
<h2>changelog</h2>
<ul>
<li>
<p>v1.6.13
<code>*</code> fix color Log</p>
</li>
<li>
<p>v1.6.3
<code>*</code> fix Log</p>
</li>
<li>
<p>v1.6.1
<code>*</code> fix saver</p>
</li>
<li>
<p>v1.4.1
<code>*</code> add <code>pathToRoutes</code></p>
</li>
<li>
<p>v1.4.0
<code>*</code> add <code>pathToTree</code> to calc react router path</p>
</li>
<li>
<p>v1.3.21
<code>*</code> modify colorUtil</p>
</li>
<li>
<p>v1.3.19
<code>*</code> modify colorUtil
<code>*</code> modify <code>utils#getFileExtension</code>
<code>*</code> modify <code>index.d.ts</code></p>
</li>
<li>
<p>v1.3.14
<code>*</code> modify cookie encode method
<code>+</code> browser/indexDB</p>
</li>
<li>
<p>v1.3.13
<code>+</code> htmlEncode
<code>+</code> implementEncode</p>
</li>
</ul></article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Sat Dec 27 2025 14:28:25 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/search.js" defer></script>
</body>
</html>