amos-tool
Version:
amos ui tool
1,452 lines (1,394 loc) • 50.1 kB
TypeScript
/// <reference types="node" />
export type RGBA = {
r: string | number;
g: string | number;
b: string | number;
a: string | number;
};
export class Base64 {
constructor();
/**
* 加密字符串
* @param input
*/
encode(input: string): string;
/**
* 解密字符串
* @param input
*/
decode(input: string): string;
}
/**
* DES加密 / 解密
* @author ilex.h
*/
declare namespace DES {
/**
* 加密字符串
* @param data
* @param secretKey 秘钥,支持单秘钥以及二级和三级秘钥 `abcde` 和 `a,b` 和 `a,b,c` 等
* @example
* DES.encode('hello', 'test'); // DES.DesCore.encode(data, 'test');
* DES.encode('hello', ','); // DES.DesCore.encode(data, ',');
* DES.encode('hello', 'a,'); // DES.DesCore.encode(data, 'a', '');
* DES.encode('hello', 'a,b,c'); // DES.DesCore.encode(data, 'a', 'b', 'c');
*/
export function encode(data: string, secretKey: string): string;
/**
* 解密字符串
* @param data
* @param secretKey
*/
export function decode(data: string, secretKey: string): string;
}
declare namespace Browser {
/**
* is firefox
*/
export function isFirefox(): boolean;
export function isIE(): boolean;
export function isEdge(): boolean;
export function isChrome(): boolean;
export function isSafari(): boolean;
/**
* is windows phone
*/
export function wp(): boolean;
export function android(): boolean;
}
declare namespace CloneTools {
export function simpleClone(o: object | Array<any>): object | Array<any>;
export function clone(o: any): object | Array<any>;
export function cloneAll(o: any): any;
}
declare namespace cookie {
/**
* Parse a cookie header.
*
* Parse the given cookie header string into an object
* The object has the various cookies as keys(names) => values
*
* @param str
* @param [options]
*/
export function parse(str: string, options?: object): object;
/**
* Serialize data into a cookie header.
*
* Serialize the a name value pair into a cookie string suitable for
* http headers. An optional options object specified cookie parameters.
*
* serialize('foo', 'bar', { httpOnly: true })
* => "foo=bar; httpOnly"
*
* @param name
* @param val
* @param options
*/
export function serialize(name: string, val: string, options?: object): string;
}
declare namespace List {
class ArrayList {
constructor();
size(): number;
values(): any[];
isEmpty(): boolean;
iterator(fn: () => {}): void;
get(index: number): any;
add(value: any): void;
addAll(value: List.ArrayList): void;
set(index: number, value: any): void;
remove(value: any): void;
removeAt(index: number): void;
indexOf(value: any): void;
clear(): void;
insert(index: number, value: any): void;
updateValue(key: number, value: any): void;
}
export function parse2string(): any;
export function parse2object(): any;
export function simpleEqual(): boolean;
export function isObject(): boolean;
}
declare namespace Queue {
export function push(obj): void;
export function pop(): Array<any>;
export function head(): Array<any>;
export function tail(): Array<any>;
export function length(): number;
export function empty(): boolean;
export function clear(): void;
}
declare namespace UUID {
/**
*
* @param len uuid 的字符长度
* @param radix 位数,默认为 62
* @example
* UUID.uuid(); // 7ED03492-919F-40D0-89D2-C53194F4A83D
*/
export function uuid(len: number, radix: number): string;
/**
* @example
* UUID.uuidFast(); // E581CCDD-189C-482D-BE21-620863F423F9
*/
export function uuidFast(): string;
/**
* @example
* UUID.uuidCompact(); // 090c3e83-ea67-45c4-b7dc-47c20eaea91e
*/
export function uuidCompact(): string;
/**
* 获取 uid,以 Date.now() 为随机参照值
* @param flag 是否显示短杠,为 true 则去掉单杠
* @example
* UUID.uuidTime(); // 6fcac0c8-e7de-44e4-ada7-c1de03a45ad5
* UUID.uuidTime(true); // 5eb47f42a03c48e6ae6804a2517a1db4
*/
export function uuidTime(flag: boolean): string;
/**
* @param prefix
* @example
* UUID.timeUUID(); // amos-timeuuid-1663831567208-1
*/
export function timeUUID(prefix: string): string;
/**
* @param prefix
* @example
* UUID.longTimeUUID(); // longtime-202209221526-1
*/
export function longTimeUUID(prefix: string): string;
/**
*
* @param tpl
* @example
* UUID.otherUUID(); // 6afe5aaf614eb8b00bf4bcd11a
*/
export function otherUUID(tpl: string): string;
}
declare namespace consts {
/**
* value 1, 大于
*/
export const GREATER: number;
/**
* value 2, 等于
*/
export const EQUAL: number;
/**
* value 3, 大于
*/
export const LESS: number;
/**
* value 4, 大于等于
*/
export const GREATER_EQUAL: number;
/**
* value 5, 小于等于
*/
export const LESS_EQUAL: number;
}
declare namespace LocationParam {
export function parse(paramString: string): object;
export function paramSearch(_name: string, target: string): void;
/**
* - 获取 location 中的所有参数
* - 对 location.href 进行查找,支持 hash 方式的路由
*/
export function getLocationParams(): object;
/**
* - 获取 location 中的参数。
* - 采用 location.search 进行查找,因此,如果采用 react-router hash 方式,将无法获取到参数
* - why not support hash router? because in hash router location.search=''
* - since v1.6.2 add hash supported
* @param name
* @example
* // href='http://47.92.103.240:8090/#/?_k=jxwq5h&token=3355&id=666'
* getLocationParamByName('token'); // 3355
* // href='http://47.92.103.240:8090?mmm=jxwq5h&token=3355&id=666'
* getLocationParamByName('token'); // 3355
*/
export function getLocationParamByName(name: string): string | null;
/**
* 获取指定 url 中的参数,匹配 # 和 &
* @param url
* @param name
*/
export function getParameter(url: string, name: string): string | '';
/**
* 获取指定 url 中的参数,仅匹配 &
* @param url
* @param name
* @example
* extractParam('/vizmixpub?appId=1536262837746302978&id=1536264796842786817&designerType=vizmix&isPreview=true', 'id'); // 1536264796842786817
*/
export function extractParam(url: string, name: string): string | null;
/**
* 获取 url 中参数集合
* @param url
* @example
* extractParam('/vizmixpub?appId=1536262837746302978&id=1536264796842786817&designerType=vizmix&isPreview=true', 'id');
* // { appId: '1536262837746302978', id: '1536264796842786817', designerType: 'vizmix', isPreview: 'true' }
*/
export function extractParams(url: string): Object;
/**
* 获取 url 中参数集合
* @param url
* @param decode 是否解码, 默认为 false
* @example
* extractParamAll('/vizmixpub?appId=1536262837746302978&id=1536264796842786817&designerType=vizmix&isPreview=true', 'id');
* // { appId: '1536262837746302978', id: '1536264796842786817', designerType: 'vizmix', isPreview: 'true' }
*/
export function extractParamAll(url: string, decode?: boolean): Object;
/**
* 补全参数
* @param {Object} param
* @param {String} url 可以为空,如果为空,则默认取 location.href
* @param {Boolean} forceCast 强制转换,默认会将参数中的 undefined 和 null 转化为 '' 字符串
* @example
* // 如:window.location.href = http://localhost:8080/aaa
* // 传入一个参数,url 将使用 `window.location.href`
* completeParam({ token: 'xxddf' }); // `http://localhost:8080/aaa?token=xxddf`
* // 使用自定义的 url
* completeParam({ token: 'xxddf' }, '/main/sub'); // `/main/sub?token=xxddf`
* // 强制转化 null 值
* completeParam({ token: 'xxddf', id: null }, '/main/sub', true); // `/main/sub?token=xxddf&id=`
* // 使用 location.href, 传入两个参数,强制转化 null 值
* completeParam({ token: 'xxddf', id: null }, true); // `http://localhost:8080/aaa?token=xxddf&id=`
*
* // 叠加值,该方法只会叠加参数,如果需要更新已有字段,以及叠加参数,可以使用 `changeParam`
* completeParam({ token: 'aa-bb-cc', id: '654321' }, 'a/b/c?token=aaa&id=bcdef'); // `a/b/c?token=aaa&id=bcdef&token=aa-bb-cc&id=654321`
*/
export function completeParam(param: Object, url: string, forceCast: Boolean): string;
/**
* 替换 url 参数。如果url中无指定的参数,则自动追加。
*
* 自动将对象中的 undefined 值,转化为 ''。null 值则直接返回 null 字符串。
*
* params 参数中的数据格式,建议调用处统一处理为 string 格式。内部仅统一处理 undefined 和 {} 格式。
* @param href 需要替换参数的 url。为空字符串则直接返回 href
* @param params 参数对象。为空对象,则直接返回 href。
* @example
* // 无参数,自动追加
* changeParam('a/b/d/g', { a: 1, b: 2, c: 3 }); // 'a/b/d/g?a=1&b=2&c=3'
* // 更新已有参数的值
* changeParam('a/b/d/g?a=aa&b=bb&c=cc', { a: 1, b: 2, c: 3 }); // 'a/b/d/g?a=1&b=2&c=3'
* // url 中无参数 d,自动追加参数
* changeParam('a/b/d/g?a=aa&b=bb&c=cc', { a: 1, b: 2, c: 3, d: 5 }); // 'a/b/d/g?a=1&b=2&c=3&d=5'
* // undefined 值转化为 ''
* changeParam('a/b/d/g', { a: 1, b: 2, c: undefined }); // 'a/b/d/g?a=1&b=2&c='
* // null 值转化为 'null'
* changeParam('a/b/d/g', { a: 1, b: null, c: undefined }); // 'a/b/d/g?a=1&b=null&c='
* // [] 和 {} 值。最好不要给参数中传入 {} 值
* changeParam('a/b/d/g', { a: { m: 3 }, b: [1,2] }); // a/b/d/g?a={"m":3}&b=1,2
* // 更换 token={token} 值,注意 原理并不是替换 {token} 值,而是更新 `token=xxx` 值,也就是目标是 `=` 左边的 `key` 与 params 中的 key 匹配
* changeParam('a/b/d/g?token={token}', { a: 'file', b: [1,2], token: 'mytoken' }); // a/b/d/g?token=mytoken&a=file&b=1,2
*/
export function changeParam(href: String, params: Object): String;
/**
* encode 参数中的值
* @param param
* @param keys 需要执行 encode 的字段
* @param processor 自定义 encode 方法,默认采用 `encodeURIComponent`
* @example
* encodeParam({ name: 'ilex', email: 'aa@qq.com' }, 'email'); // { name: 'ilex', email: 'aa%40qq.com' }
* encodeParam({ info: { hobby: 'coding', phone: '155666688881' } }, 'info'); // { info: '%7B%22hobby%22%3A%22coding%22%2C%22phone%22%3A%22155666688881%22%7D' }
* encodeParam({ split: [1,2,3] }, 'split'); // { split: '%5B1%2C2%2C3%5D' }
* encodeParam({ star: 18 }, 'star', v => v * 2); // { star: 36 }
*/
export function encodeParam(param: {}, keys: String | String[], processor: (arg) => String): {};
/**
* 更新浏览器地址栏地址
* @param param
* @param href 指定的地址,如果不指定,则采用 location.href
*/
export function replaceUrl(param: Object, href?: String): void;
export type LocationSearch = { init(): void; getValue(key: string): string; getParameters(): Array<any> };
export type LSFN = { getValue(): string; getParameters(): Array<any> };
}
declare namespace pwdPolicy {
export function normalPolicy(password: string): object;
export function advancePolicy(password: string, secretKey: string): object;
export function useMd5Policy(password: string, secretKey: string): object;
}
declare namespace random {
export function random(length: number): string;
export function randomInt(min: number, max: number): number;
}
/**
* Store 工具集合,支持 cookie 、localStorage和sessionStorage
* 支持 base64 加密解密
*/
declare namespace Store {
/**
* 加密 base64
* @param str
*/
export function encrypt(str: string): string;
/**
* 解密 base64
* @param str
*/
export function decrypt(str: string): string;
export function setCookieByDays(name: string, value: any, days: number): void;
export function getAllCookies(): Array<any>;
/**
* set cookie
* @param name
* @param value
* @param hour
* @return void
*/
export function setCookieByHour(name: string, value: string, hour: number): void;
/**
* read cookie
*
* @param name cookie key
* @return cookie value
*/
export function getCookieByName(name: string): string | null;
/**
* 移除cookie
* @param name
*/
export function removeCookieByName(name: string): void;
/**
* 移除所有cookie
*/
export function clearAllCookie(): void;
/**
* localStorage 工具
*/
export namespace lsTool {
export const localStorage: any;
export function read(key: string): any;
export function write(key: string, data: string): any;
export function each(fn: (value: string, key: string) => {}): void;
export function remove(key: string): void;
export function fuzzyRemove(fn: (key: String) => Boolean): void;
export function allKeys(): String[];
export function clearAll(): void;
}
/**
* sessionStorage 工具
*/
export namespace session {
export const sessionStorage: any;
export function read(key: string): any;
export function write(key: string, data: string): any;
export function each(fn: (value: string, key: string) => {}): void;
export function remove(key: string): void;
export function fuzzyRemove(fn: (key: String) => Boolean): void;
export function allKeys(): String[];
export function clearAll(): void;
}
}
declare namespace strUtils {
/**
* 首字母大写
* @param str
*/
export function toCapitalStr(str: string): string;
/**
* 驼峰化, 仅支持首字母大写、或者采用中杠连接的两个字母首字母大写
* 如果要支持其它输入,将正则改为: /(-|(\s+)|_)(\w)/g
*
* @param {String} name
* @returns {String}
*/
export function camelCase(name: string): string;
/**
* 将中缸连接的字符串 驼峰化
*
* hello-world => hellWorld
* Hello-world => hellWorld
* Hello-World => hellWorld
*
* @param {any} name
* @returns {String}
*/
export function transCamel(name: string): string;
/**
* 字符串首字母大写
* @param {String} str
* @returns {String}
*/
export function capFirst(name: string): string;
/**
* 获取字符串的hashCode码
* @param {String} str
* @returns {String} string | null
*/
export function hashCode(name: string): string;
/**
* 进制与单位处理
* @param {String | Number} value 要处理的值
* @param {Object} fmtOpt
* @param {String} fmtOpt.prefix 前缀
* @param {String} fmtOpt.suffix 后缀
* @param {Boolean} fmtOpt.selfenable 自定义进制是否启用
* @param {String} fmtOpt.selfscale 进制
* @param {String} fmtOpt.selfunit 单位
* @param {Number} fmtOpt.fixnumber 小数位数
* @param {Boolean} fmtOpt.fillzero 空位补0
* @param {Boolean} fmtOpt.thousandsplitchar 千分位分隔符
*/
export function dealScaleAndUnit(value: string, fmtOpt: Object): string;
/**
* 转化为 utf8
* @param str
*/
export function toUTF8(str: string): string;
}
declare namespace tableFilter {
export function getChildrenlength(children): number;
export function flatToHierarchy(arr): Array<any>;
export function filterParentPosition(arr): Array<any>;
export function isInclude(smallArray, bigArray): boolean;
export function filterAllCheckedData(vals, treeData): Array<any>;
export function recombineFlatData(value, treeData): Array<any>;
export function recombineData(value, treeData): Array<any>;
export function filterChilds(value, treeData): Array<any>;
export function fileterAllMatchedData(value, arr): Array<any>;
export function recursive(children, cb): void;
export function filterTreeLevel(datas, filterFn, options): Array<any>;
}
declare namespace canvas2img {
export function saveAsImage(canvas, width, height, type): void;
export function saveAsPNG(canvas, width, height): void;
export function saveAsJPEG(canvas, width, height): void;
export function saveAsGIF(canvas, width, height): void;
export function saveAsBMP(canvas, width, height): void;
export function convert2Image(canvas, width, height, type): HTMLImageElement;
export function convert2data(canvas, type, width, height): string;
export function convert2Blob(canvas, fn, options): any;
export function convert2PNG(canvas, width, height): any;
export function convert2JPEG(canvas, width, height): any;
export function convert2GIF(canvas, width, height): any;
export function convert2BMP(canvas, width, height): any;
}
declare namespace eventHelper {
export function stopPropagation(e: Event): void;
export function preventDefault(e: Event): void;
export function stopEvent(e: Event): void;
export function addHandler(element: HTMLElement, type: string, handler: Function): void;
export function removeHandler(element: HTMLElement, type: string, handler: Function): void;
}
declare namespace canvasTools {
export function drawPolygon(ctx, options): void;
}
declare namespace colorUtil {
/**
* RGB颜色转换为16进制
* @param stringRgb
* @example
* toStringHexColor('rgba(241,112,19,1)'); // #f17013
* toStringHexColor('rgba(241,112,19, 0.1)'); // #f1701319
*/
export function toStringHexColor(stringRgb: string): string;
/**
* - 转化为hex颜色 (仅支持 RGB),如果是 rgba 时,则舍去 a。
* - 如果传入的是 key color 则直接转化为与之对应的 hex 值
* @param {string} stringRgb
* @example
* toHexColor('rgba(241,112,19)'); // #f17013
* toHexColor('rgba(241,112,19, 1)'); // #f17013
* toHexColor('rgba(241,112,19, 0.1)'); // #f17013
* toHexColor('red'); // #ff0000
* toHexColor(); // ''
* toHexColor(null); // ''
* toHexColor(123456); // ''
* toHexColor(0x123456123456); // ''
*/
export function toHexColor(stringRgb: string): string;
/**
* 16进制颜色转为RGB格式
* @param hexColor
* @example
* toRGBcolor('#AABBCC'); // rgb(170,187,204)
*/
export function toRGBcolor(hexColor): string;
/**
* 将16进制的颜色转换为rgb
* @param hexColor
* @example
* transformColor('#AABBCC'); // rgb(170,187,204)
*/
export function transformColor(hexColor: string): string;
export function isHexColor(color: string): boolean;
/**
* 判断是否是内置 英文 color
* @param color
* @example
* isKeyColor('red'); // true
* isKeyColor('yellow'); // true
* isKeyColor('asdfasdfa'); // false
*/
export function isKeyColor(color: string): boolean;
export function isRgbColor(color: string): boolean;
/**
* 将rgb颜色转化成object
* @param color
* @example
* '12,12,12,12' => {r:12,g:12,b:12,a:12}
* 'rgba(12,12,12,12)' => {r:12,g:12,b:12,a:12}
*/
export function rgb2object(color: string): RGBA;
/**
* 将object的rgb转化成string
* @param color
* @example
* objRGB2str({ r:1, g:1, b:1, a:1 }); // 'rgba(1,1,1,1)'
* objRGB2str({ r:1, g:1, b:1, a:0 }); // 'rgba(1,1,1,0)'
* objRGB2str({ r:1, g:1, b:1 }); // 'rgba(1,1,1)'
*/
export function objRGB2str(color: object): string;
/**
* key color 转化为 hex color。
* 如果不是 key color 则直接返回 color 自身
* @param color
*/
export function keyColorToHex(color: string): string;
/**
* 产生渐变色函数
* @param color
* @param minValue
* @param maxValue
*/
export function gradientColor(color: Object, minValue: number, maxValue: number): any;
}
declare namespace randomColor {
export function randomHexColor(): string;
export function randomRgbColor(): string;
export function randomHexColorStr(): string;
}
declare namespace qs {
export type formats = {
default: 'RFC3986';
formatters: {
RFC1738(value: string): string;
RFC3986(value: string): any;
};
RFC1738: 'RFC1738';
RFC3986: 'RFC3986';
};
export function parse(str: string, opts: Object): any;
export function stringify(object: Object, opts: Object): string;
}
/**
* 转码URL中的特殊字符
*
* 特殊字符说明
* 1. '+' URL 中+号表示空格 %2B
* 2. '空格' URL中的空格可以用+号或者编码 %20
* 3. '/' 分隔目录和子目录 %2F
* 4. '?' 分隔实际的 URL 和参数 %3F
* 5. '%' 指定特殊字符 %25
* 6. '#' 表示书签 %23
* 7. '&' URL 中指定的参数间的分隔符 %26
* 8. '=' URL 中指定参数的值 %3D
*
* @param url
* @return new url
* @example
* encodeUrl('http://localhost:3000/login?user=123&pwd=123'); // http://localhost:3000/login?user%3D123%26pwd%3D123
*/
export function encodeUrl(url: string): string;
/**
* restful风格路径参数替换
*
* @param url
* @param options
* @param regexps
*
* @example
* const _url = 'a/b/{id}'
* const url = restfulUrl(_url, { id: '123' }, [regex]); => 'a/b/123'
*/
export function restfulUrl(url: string, options: {}, regexps: RegExp): string;
/**
*
* @param str
* @param key
* @param raw
* @returns md5 value
* @example
* // calc the (hex-encoded) MD5 hash of a given string value:
* var hash = md5("value"); // "2063c1608d6e0baf80249c42e2be5804"
* // calc the (hex-encoded) HMAC-MD5 hash of a given string value and key:
* var hash = md5("value", "key"); // "01433efd5f16327ea4b31144572c67f6"
* // calc the raw MD5 hash of a given string value:
* var hash = md5("value", null, true);
* // calc the raw HMAC-MD5 hash of a given string value and key:
* var hash = md5("value", "key", true);
*/
export function MD5(str: string, key: string, raw: boolean): string;
/**
* deep copy
* 1. obj 中包含方法,则直接赋值
* @param source
*/
export function deepCopy(source: any): any;
/**
* deep equal use stringfy
* @param valA
* @param valB
*/
export function deepEqual(valA: any, valB: any): boolean;
/**
* deep equal
* support: Object/Array/String/Number/RegExp/
* @param valA
* @param valB
*/
export function fastDeepEqual(a: any, b: any): boolean;
/**
*
* 函数节流,控制相关事件提交间隔
* @param fn
* @param data 执行的数据
* @param context 执行函数的上下文 可以为null [默认为null]
* @param delay 两次事件触发间隔 [默认间隔500ms]
* @param mustApplyTime l两次执行时间差 [可选, 不传递参数时,默认间隔0ms]
*
* @example 简单使用方式:
* 1.const fn = (data) =>console.log(data);
* 2.点击事件: handleClick = (e) => funcThrottle(fn, e.target.value);
*
* @author ilex
*/
export function funcThrottle(fn: () => {}, data: any, context: any, delay: number, mustApplyTime: number): void;
export function isNode(): boolean;
export function objectAssign(target, source): any;
export function objectEntries(obj): any;
export function objectValues(obj): any;
/**
* 删除多余属性
* @param obj 目标对象
* @param keys 需要删除的键
* @example
* omit({ name: 'ilex', age: 16 }, ['age']); // { name: 'ilex' }
*/
export function omit(obj: object, keys: string | Array<String>): any;
/**
* 从指定的 obj 中获取 指定的key组成新的对象
* @param obj
* @param keys
* @example
* pick({ name: 'ilex', age: 16 }, ['age']); // { age: 16 }
* pick({ name: 'ilex', age: 16 }, ['']); // {}
* pick({ name: 'ilex', age: 16 }, ['you']); // {},如果指定对象中无指定的 key,则不拾取
*/
export function pick(obj: Object | Function, keys: string | Array<String>): Object;
/**
* 从指定的 obj 中获取 满足 judge(key, value) 组成新的对象
*
* @param obj
* @param judge
* @example
* pickBy({ a: 1, b: 2, c: 'ray' }, (key, value) => typeof value === 'number')
*/
export function pickBy(obj: Object | Function, judge: (key, value) => Boolean): Object;
/**
* 将数据转化为json
* @param data
*/
export function parseJson(data: any): any;
/**
* 将object等 类型的数据转化为string
* @param json
*/
export function stringify(json: any): any;
/**
* 是否支持websocket
*/
export function supportWs(): boolean;
export function trim(str: string | null | undefined): string;
export function array2tree(data, filterFn, options): Array<any>;
export function arrayFilter(data, options): Array<any>;
declare namespace arrayUtils {
/** 数组交集 */
export function arrayIntersection(first: [], ...args): [];
/**
* array to object
* @param source
* @param options
*/
export function arrayToObject(source: [], options: { plainObjects: Boolean }): {};
/**
* 数组去重和排序
* @param source 原始数组
* @param compareFn 排序方法
*/
export function deduplicateAndSort(source: [], compareFn: (a: any, b: any) => number): [];
/**
* 通过索引删除数组指定位置的数据。
*
* 如果 index 是数组,执行时会先进行去重,然后升序处理
* @param source
* @param index 数组索引(下标)
*/
export function removeByIndex(source: [], index: Number | Number[]): [];
/**
* 计算数组的 秩
* @param numbers
* @see https://support.minitab.com/zh-cn/minitab/help-and-how-to/statistics/nonparametrics/how-to/kruskal-wallis-test/methods-and-formulas/methods-and-formulas/#average-rank
*/
export function calculateRanks(numbers: []): [];
/**
* 要将两个二维数组按照主对角线方向合并
* @param arr1
* @param arr2
* @example
* const array1 = [[1, 2], [3, 4]];
* const array2 = [[5, 6], [7, 8]];
* merge2DArraysDiagonally(array1, array2); // 输出: [[1, 2, 5, 6], [3, 4, 7, 8]]
*/
export function merge2DArraysDiagonally(arr1: any[][], arr2: any[][]): any[][];
export const moveIndex = {
/**
* 数组向后移动一位(索引变大,最大索引值必须小于等于 arr.length - 1)
* @param arr
* @param indices
* @returns
*/
next(arr: any[], indices: Number[]) {
return arr;
},
/**
* 数组向前移动一位 (索引变小,最小值必须大于等于1)
* @param arr
* @param indices
* @returns
*/
prev(arr: any[], indices: Number[]){
return arr;
}
};
}
declare namespace algor {
/**
* Computes the sample ranks for the values of an array-like object.
* @see https://support.minitab.com/zh-cn/minitab/help-and-how-to/statistics/nonparametrics/how-to/mann-whitney-test/methods-and-formulas/methods-and-formulas/
* @param x data array
* @param options options object
* @param options.method [options.method='average'] method name determining how ties are treated
* @param options.missing [options.missing='last'] determines where missing values go (`first`,`last`, `*`, or `remove`) `*` is same with `last`, only replace `value` to `null`
* @param options.missing [options.encoding=[null,NaN]] array of values encoding missing values
* @example
* ranks( [ 1.1, 2.0, 3.5, 0.0, 2.4 ] ); // [ 2, 3, 5, 1, 4 ]
* ranks( [ 21.6, 12.5, 8.91, 4.0, 1.8, 1.0, 1.0, 0.8, 2.35, 4.4, 3.8, 7.4, 4.3, 19.05, 36.2 ] ); // [ 14, 12, 11, 7, 4, 2.5, 2.5, 1, 5, 9, 6, 10, 8, 13, 15 ]
*
* @example
* // Ties are averaged:
* ranks( [ 2, 2, 1, 4, 3 ] ); // [ 2.5, 2.5, 1, 5, 4 ]
*
* @example
* // Missing values are placed last:
* ranks( [ null, 2, 2, 1, 4, 3, NaN, NaN ] ); // [ 6, 2.5, 2.5, 1, 5, 4, 7 ,8 ]
*/
export function ranks(x: Array<Number>, options: { method: String, missing: String, encoding?: [] }): [];
}
/**
* check browser support
*
* @param supBrowser browsers
* @param matchs the options of matchs
* @example
* normal:
const support = browserSupport(['firefox/', 'chrome/'], {
'firefox/': { limit: consts.GREATER_EQUAL, version: 50 },
'chrome/': { limit: consts.GREATER_EQUAL, version: 55 }
});
ie:
const support = browserSupport(['firefox/', 'chrome/', 'ie'], {
'firefox/': { limit: consts.GREATER_EQUAL, version: 50 },
'chrome/': { limit: consts.GREATER_EQUAL, version: 55 },
'ie': { limit: consts.GREATER_EQUAL, version: 9 }
});
*/
export function browserSupport(supBrowser: Array<any>, matchs: object): boolean;
declare namespace completeUnit {
/**
* complete unit
* @param val value
* @param tag unit tag default is 'px'
*/
export function completeUnit(val: number | string, tag: string): string;
/**
*
* @param val 转化为 pixel
* @example
* toPixel('12'); // 12px
* toPixel('12rem'); // 12rem
* toPixel('12px'); // 12px
* toPixel('auto'); // auto
* toPixel('15%'); // 15%
* toPixel('calc(100% - 16px)'); // calc(100% - 16px)
* toPixel(false); // false
* toPixel(true); // true
* toPixel(); // undefined
*/
export function toPixel(val: number | string): string;
}
export class objectPath {
/**
* tests path existence
* @param obj
* @param path
* @example
* objectPath.has(obj, "a.b"); // true
* objectPath.has(obj, ["a","d"]); // false
*/
has(obj: Object, path: number | string): boolean;
ensureExists(obj: Object, path: number | string, value: any): boolean;
set(obj: Object, path: number | string, value: any, doNotReplace: boolean): void;
empty(obj: Object, path: number | string): void;
push(obj: Object, path: number | string, values?: any): void;
coalesce(obj: Object, paths: Array<Number|String>, defaultValue: any): void;
/**
* 获取指定路径节点
* @param obj
* @param path
* @param defaultValue
* @example
* // bind object
var model = objectPath({
a: {
b: "d",
c: ["e", "f"]
}
});
//now any method from above is supported directly w/o passing an object
model.get("a.b"); //returns "d"
*/
get(obj: Object, path: Number|String, defaultValue: any): any;
/**
* 删除指定路径节点
* @param obj
* @param path
* @example
* model.del("a.b"); // obj.a.b is now undefined
*/
del(obj: Object, path: Number|String): string;
create(options: Object): Function;
withInheritedProps: Function;
}
/**
* 解析数据
* @param text
* @param dataObj
* @param regexps 可选
* @returns returns a new str
* @example
* demo: parseText('a/{b}/{c}/d',{a: 1, b:2}) 返回: 'a/1/2/d'
* demo: parseText('a/b?name={name}&pwd={pwd}',{name: 'ilex', pwd:122}) 返回: 'a/b?name=ilex&pwd=123'
*/
export function parseText(text: string, dataObj: object, regexps?: string | RegExp): string;
export function shallowEqual(objA, objB): boolean;
export function downloadFile(options): void;
export function amountCase(n): string;
export function pwdStrength(str): number;
export function addition(arg1, arg2): number;
export function subtraction(arg1, arg2): number;
/**
* 小数乘法
* @param arg1 被乘数(接受小数和整数)
* @param arg2 乘数(接受小数和整数)
* @param fix 乘积保留几位(接受正负整数以及0),默认值为 0
* @returns {Number}
* @example
* accMul(0.56, 100); // 56
* accMul(0.5679, 100); // 57
* accMul(0.5679, 100.2); // 57
*/
export function accMul(arg1: Number, arg2: Number, fix?: Number): number;
/**
* 小数除法
* @param arg1 被乘数(接受小数和整数)
* @param arg2 乘数(接受小数和整数)
* @param fix 除法保留几位(接受正负整数以及0),默认值为 0
* @returns {Number}
* @example
* accDivide(56, 100); // 0.56
* accDivide(5679, 100, 2); // 56.79
* accDivide(5679, 100.2, 2); // 56.68
*/
export function accDivide(arg1: Number, arg2: Number, fix?: Number): number;
/**
* 将数值格式化成金额形式
*
* @param num 数值(Number或者String)
* @param precision 精度,默认不变. 传 null or undefined
* @param separator 分隔符,默认为逗号
* @param sign 前缀,默认为$
* @param unit 单位,默认为空
* @return 金额格式的字符串,如'1,234,567',默认返回 ''
*/
export function coinFormat(num: number, precision: number, separator: string, sign: string, unit: string): string | '';
/**
* dateTime
*/
declare namespace dateTime {
/**
* 将日期时间戳格式化成指定格式
* @param date
* @param fmt 默认 yyyy-MM-dd HH:mm:ss
* @example
* formatDate(); // 2016-09-02 13:17:13
* formatDate(new Date(), 'yyyy-MM-dd'); // 2016-09-02
* formatDate(new Date(), 'yyyy-MM-dd 第q季度 www HH:mm:ss:SSS');// 2016-09-02 第3季度 星期五 13:19:15:792
* formatDate(1472793615764); // 2016-09-02 13:20:15
*/
export function formatDate(date: Date | number, fmt: string): string;
/**
* 时间戳转时间,这是另一种方式 2018-07-09 11:04:51
*
* @param date
* @returns string
*/
export function timetrans(date: Date | number): string;
/**
*将一个日期格式化成友好格式,比如,1分钟以内的返回“刚刚”,当天的返回时分,当年的返回月日,否则,返回年月日
*
* @param date
* @returns string
*/
export function formatDateToFriendly(date: Date | number): string;
/**
* 将一段时长转换成友好格式
* @param time
* @returns string
* @example
* var str = friendlyDate('1311111119999'); // 6年前(括号里的字符串值为1970年距字符串值表示的时间的毫秒数)
* var str2 = friendlyDate('1503190042273'); // 1天前
*/
export function friendlyDate(time: number): string;
/**
* 将一段时长转换成友好格式
* @param second
* @returns string
* @example
* 147->“2分27秒”
* 1581->“26分21秒”
* 15818->“4小时24分”
*/
export function formatDurationToFriendly(second: number): string;
/**
* 将时间转换成MM:SS形式
* @param second
*/
export function formatTimeToFriendly(second: number): string;
/**
* 判断某一年是否是闰年 可以是一个date类型,也可以是一个int类型的年份,不传默认当前时间
* @param year
*/
export function isLeapYear(year: number): string;
/**
* 获取某一年某一月的总天数,没有任何参数时获取当前月份的
* @param date
* @param month
* @example
* 方式一:$.getMonthDays();
* 方式二:$.getMonthDays(new Date());
* 方式三:$.getMonthDays(2013, 12);
*/
export function getMonthDays(date: Date | number, month: number): string;
/**
* 计算两个日期之间的天数,用的是比较毫秒数的方法
* 传进来的日期要么是Date类型,要么是yyyy-MM-dd格式的字符串日期
* @param date1 日期一
* @param date2 日期二
*/
export function countDays(date1: Date | number, date2: Date | number): string;
/**
* 将字符串解析成日期
* @param str 输入的日期字符串,如'2014-09-13'
* @param fmt 字符串格式,默认'yyyy-MM-dd',支持如下:y、M、d、H、m、s、S,不支持w和q
* @returns 解析后的Date类型日期
* @example
* parseDate('2016-08-11'); // Thu Aug 11 2016 00:00:00 GMT+0800
* parseDate('2016-08-11 13:28:43', 'yyyy-MM-dd HH:mm:ss') // Thu Aug 11 2016 13:28:43 GMT+0800
*/
export function parseDate(str: string, fmt: string): string;
/**
* 到某一个时间的倒计时
* @param endTime
* @example
* getEndTime('2017/7/22 16:0:0') // result:"剩余时间6天 2小时 28 分钟20 秒"
*/
export function getEndTime(endTime: string | number): object;
/**
* 到某一个时间的倒计时
* @param endTime
* @example
* getEndTimeStr('2017/7/22 16:0:0') // "剩余时间6天 2小时 28 分钟20 秒"
*/
export function getEndTimeStr(endTime: string | number): string;
/**
* 获取某月有多少天
* @param time
*/
export function getMonthOfDay(time: string | number): string;
/**
* 获取某年有多少天
* @param time
*/
export function getYearOfDay(time: string | number): string;
/**
* 获取某年的第一天
* @param time
*/
export function getFirstDayOfYear(time: string | number): string;
/**
* 获取某年最后一天
* @param time
*/
export function getLastDayOfYear(time: string | number): string;
/**
* 获取某个日期是当年中的第几天
* @param time
*/
export function getDayOfYear(time: string | number): string;
/**
* 获取某个日期在这一年的第几周
* @param time
*/
export function getDayOfYearWeek(time: string | number): string;
/**
* 获取两个时间段差多久
* @param time
* @param fmt
*/
export function timeFn(str: string, fmt: string): string;
}
export type Direction = 'up' | 'down' | 'left' | 'right';
export type Align = 'top' | 'right' | 'bottom' | 'left' | 'middle';
/**
* position factory
* @param triggerNode
* @param popoverNode
* @param direction
* @param align
*/
export function positionFactory(triggerNode: HTMLElement, popoverNode: HTMLElement, direction: Direction, align: Align): any[];
/**
* amostool
*/
declare namespace amostool {}
/**
* amostool utils
*/
declare namespace utils {
export function isString(value: any): boolean;
export function isArray(value: any): boolean;
export function isObject(value: any): boolean;
export function isBoolean(value: any): boolean;
export function isFunction(value: any): boolean;
/**
* 判断 number,采用正则表达式进行判断
* 正则表达式:/^(\-|\+)?([0-9]+(\.[0-9]+)?|Infinity)$/
* @param {*} value
*/
export function isNumber(value: any): boolean;
/**
* 支持 string 类型的科学计数 number 校验
* @param value
*/
export function isENumber(value: any): boolean;
export function isFloat(value: any): boolean;
export function isOpacity(value: any): boolean;
export function toFloat(value: any): number;
export function isNull(value: any): boolean;
export function isUndefined(value: any): boolean;
export function isNil(value: any): boolean;
/**
* 空(null、undefined、'')
* @param value
* @example
* isBlank(); // true
* isBlank(void 0); // true
* isBlank(null); // true
* isBlank(''); // true
* isBlank(NaN); // false
* isBlank(' '); // false
* isBlank(0); // false
* isBlank(false); // false
* isBlank(true); // false
*/
export function isBlank(value: any): boolean;
export function has(obj: object | Array<any>, path: Array<any> | string): boolean;
/**
* Retrieve the values of an object's properties.
* @param obj
*/
export function values(obj: object): Array<any>;
export function noop(): void;
export function isEmpty(value: any): boolean;
export function isEmptyObject(value: any): boolean;
export function isElement(value: any): boolean;
export function isHTMLElement(value: any): boolean;
export function isSVGElement(value: any): boolean;
export function isDom(value: any): boolean;
/**
* check value is url
* @param value
* @example
* isUrl('http://www.baidu.com') // true
* isUrl('https://www.baidu.com') // true
* isUrl('www.baidu.com') // false
* isUrl('http://172.16.1.2') // true
* isUrl('172.16.1.2') // false
* isUrl('/a/b/c') // false
* isUrl('main/dd/d') // false
* isUrl('http://localhost:8080/aaa') // true
*/
export function isUrl(value: string): boolean;
export function isBuiltInObject(value: any): boolean;
export function null2default(str: any): any;
/**
* 判断对象是不是Json
* Object 对象,typeof === object && toString === '[object Object]'
* @param obj
* @returns boolean true 是 false不是
*/
export function isJson(obj: any): boolean;
export function isSymbol(obj: any): boolean;
export function isNullOrUndefined(obj: any): boolean;
export function isDate(obj: any): boolean;
/**
* 判断string能否被转成json
* 参数 str 如果不是 string 则直接返回 false
* @param str
* @returns boolean
*/
export function stringIsJson(value: any): boolean;
/**
* 判断key是否在object内
* (采用 in 判断,继承属性均会判断)
* @param keys
* @param obj 如果 obj 是 null or undefined, 或者 非 object,则直接 返回 false
*/
export function isKeyInObject(keys: string | string[], obj: any): boolean;
/**
* 判断key是否在object内
* (采用 hasOwnProperty 判断,继承属性不会判断)
* @param keys
* @param obj 如果 obj 是 null or undefined, 或者 非 object,则直接 返回 false
*/
export function isOwnKeyInObject(keys: string | string[], obj: any): boolean;
/**
* 判断是否是 promise
* @param value
*/
export function isPromise(value: any): boolean;
/**
* 判断是否是正则对象
* @param value
* @example
* isRegExp(undefined); // false
* isRegExp(''); // false
* isRegExp(null); // false
* isRegExp(123); // false
* isRegExp('aa'); // false
* isRegExp(/aa/); // true
* isRegExp(new RegExp('aa')); // true
* isRegExp({ test(){} }); // false
*/
export function isRegExp(value: any): boolean;
export function simpleEqual(objA: object, objB: object): boolean;
/**
* 判断是一个 image 的路径
* `/a/a/a.png|jpe?g|gif...`
* `http://a.b/a.png|jpe?g|gif...`
* `data:image/png|jpe?g|gif;base64,`
* @param url 支持的格式 `jpe?g|png|gif|bmp|ico|tga`
* @example
* isImageSrc('/a/a/a.png'); // true
* isImageSrc('http://a.b/a.png'); // true
* isImageSrc('data:image/png|jpe?g|gif;base64,'); // true
*/
export function isImageSrc(url: String): boolean;
/**
* 判断图片是 gif
* @param url 支持的格式
* @example
* isGIF('a.gif'); // true
* isGIF('data:image/;base64,'); // true
*/
export function isGIF(url: String): boolean;
/**
* 将数字部分内容转化为 *
* @param number 目标 Number
* @param start 起始位置 默认3
* @param len 转换位数 默认4
* @param sign 替换的字符 默认*
*/
export function encodeNumber(number: Number, start?: number, len?: number, sign?: string): String;
/**
* 获取扩展名
*
* 可快速使用 `filePath.split('.').pop();` 获取扩展名
* @param filePath
* @return {String} ext
* @example
* getFileExtension('a.png'); // png
* getFileExtension('a/a/a.png'); // png
* getFileExtension('a.a.a.png.jpg'); // jpg
* getFileExtension('a'); // ''
*/
export function getFileExtension(filePath: string): String;
/**
* 将指定 size 中的数据,转化为 byte
* - 默认不区分大小写, mb/MB/Mb 均表示 mb
* - 默认去除内部所有空格, 1024 MB -> 1024mb
* - 无单位或者 number 类型,将直接转化为 number值,默认当 byte 处理
* @param size 带有单位的 size,不带单位时,直接返回该值
* @returns byte
* @example
* fileSizeToByte('1kb'); // 1024
* fileSizeToByte('1mb'); // 1048576
* fileSizeToByte('1MB'); // 1048576
* fileSizeToByte('1gb'); // 1073741824
* fileSizeToByte('1tb'); // 1099511627776
* fileSizeToByte('123'); // 123
* fileSizeToByte(123); // 123
*/
export function fileSizeToByte(size: string): String;
export function some(arr: Array<any>, fun: Function /*, thisArg */): boolean;
export function every(arr: Array<any>, callbackfn: Function, thisArg): boolean;
export function reduce(arr: Array<any>, callback: Function /*, initialValue*/);
export function parse2string(obj: object | Array<any>): string;
export function parse2object(str: string): object | Array<any>;
export function dataToArray(vars: any): Array<any>;
/**
* Those data types can be cloned:
* Plain object, Array, TypedArray, number, string, null, undefined.
* Those data types will be assgined using the orginal data:
* BUILTIN_OBJECT
* Instance of user defined class will be cloned to a plain object, without
* properties in prototype.
* Other data types is not supported (not sure what will happen).
*
* Caution: do not support clone Date, for performance consideration.
* (There might be a large number of date in `series.data`).
* So date should not be modified in and out of echarts.
*
* @param source
* @return new
*/
export function clone(source: any): object | Array<any>;
/**
* @param target
* @param source
* @param [overwrite=false]
* @return target
*/
export function merge(target: object | Array<any>, source: object | Array<any>, overwrite?: boolean): object | Array<any>;
/**
* @param targetAndSources The first item is target, and the rests are source.
* @param [overwrite=false]
* @return target
*/
export function mergeAll(targetAndSources: Array<any>, overwrite?: boolean): object | Array<any>;
/**
* 比较 objTarget 中的所有属性值,是否在 objSource 中相等
* @param objSource
* @param objTarget
*/
export function subObjectEqual(objSource: {}, objTarget: {}): Boolean;
/**
* 校验给定的 string 是否是 文件名
*
* 校验中使用的正则表达式: `/[\\/:\*\?"<>\|]/g`
* @param str
* @param maxLen
* @example
* checkFileName('example.txt'); // true
* checkFileName('con\\example.txt'); // false
* checkFileName('example:.txt'); // false
* checkFileName(' example.txt'); // false
* checkFileName('example.txt '); // false
* checkFileName('example.txt.'); // true
* checkFileName('example..............txt'); // true
*/
export function checkFileName(str: String | Number, maxLen?: 259): Boolean;
}
declare namespace throttleDebounce {
/**
* Throttle execution of a function. Especially useful for rate limiting
* execution of handlers on events like resize and scroll.
*
* @param delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
* @param [noTrailing] Optional, defaults to false. If noTrailing is true, callback will only execute every `delay` milliseconds while the
* throttled-function is being called. If noTrailing is false or unspecified, callback will be executed one final time
* after the last throttled-function call. (After the throttled-function has not been called for `delay` milliseconds,
* the internal counter is reset)
* @param callback A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,
* to `callback` when the throttled-function is executed.
* @param [debounceMode] If `debounceMode` is true (at begin), schedule `clear` to execute after `delay` ms. If `debounceMode` is false (at end),
* schedule `callback` to execute after `delay` ms.
*
* @return A new, throttled, function.
* @example
* throttle(300, () => { });
* debounce(300, () => { });
* // cancel
* const throttled = throttle(300, () => { });
* throttled.cancel();
*/
export function throttle(delay: Number, noTrailing: Boolean, callback: Function, debounceMode: Boolean): Function;
/**
* Debounce execution of a function. Debouncing, unlike throttling,
* guarantees that a function is only executed a single time, either at the
* very beginning of a series of calls, or at the very end.
*
* @param delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
* @param [atBegin] Optional, defaults to false. If atBegin is false or unspecified, callback will only be executed `delay` milliseconds
* after the last debounced-function call. If atBegin is true, callback will be executed only at the first debounced-function call.
* (After the throttled-function has not been called for `delay` milliseconds, the internal counter is reset).
* @param callback A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,
* to `callback` when the debounced-function is executed.
*
* @return A new, debounced function.
*/
export function debounce(delay: Number, atBegin: Boolean, callback: Function): Function;
}
declare const arrayMove: {
/**
Move an array item to a different position.
@param array - The array to move the item in.
@param from - Index of item to move. If negative, it will begin that many elements from the end.
@param to - Index of where to move the item. If negative, it will begin that many elements from the end.
@returns A new array with the item moved to the new position.
@example
```
import arrayMove = require('array-move');
const input = ['a', 'b', 'c'];
arrayMove(input, 1, 2);
//=> ['a', 'c', 'b']
arrayMove(input, -1, 0);
//=> ['c', 'a', 'b']
arrayMove(input, -2, -3);
//=> ['b', 'a', 'c']
```
*/
<ValueType>(array: ReadonlyArray<ValueType>, from: number, to: number): ValueType[];
/**
Moves the item to the new position in the input array. Useful for huge arrays where absolute performance is needed.
@param array - The array to modify.
@param from - Index of item to move. If negative, it will begin that many elements from the end.
@param to - Index of where to move the item. If negative, it will begin that many elements from the end.
*/
mutate(array: unknown[], from: number, to: number): void;
// TODO: Remove this for the next major release
default: typeof arrayMove;
};
declare namespace flat {
/**
* 获取树结构数据 flat keys
* @param item
* @param options 默认值为 { uniqueKey: 'key', childrenKey: 'children' }
*/
export function getTreeFlatKeys(item: Object | any[], options?: { uniqueKey?: 'key', childrenKey?: 'children' }): String[] | Number[];
}