diff --git a/src/core/func/function.js b/src/core/func/function.js index 58d8c1025..1a26b4981 100644 --- a/src/core/func/function.js +++ b/src/core/func/function.js @@ -87,7 +87,7 @@ _.extend(BI, { }; }, - afterFunc: function (func) { + afterFunc: function (sFunc, func) { var __self = sFunc; return function () { var ret = __self.apply(sFunc, arguments); diff --git a/typescript/core/func/function.ts b/typescript/core/func/function.ts new file mode 100644 index 000000000..b2c34c106 --- /dev/null +++ b/typescript/core/func/function.ts @@ -0,0 +1,29 @@ +/** + * 创建唯一的名字 + * @param array 已有的名字集合 + * @param name 待生成的名字 + * @return 生成后的名字 + */ +export declare type _createDistinctName = (array: any[], name: string) => string; + +/** + * 获取搜索结果 + * @param items 待搜索的数据 + * @param keyword 关键字 + * @param param 搜索哪个属性 + */ +export declare type _getSearchResult = (items: any, keyword: any, param: string) => {find: any, match: any} + +/** + * 在方法A执行之前执行方法B + * @param sFunc 方法A + * @param func 方法B + */ +export declare type _beforeFunc = (sFunc: Function, func: Function) => Function; + +/** + * 在方法A执行之后执行方法B + * @param sFunc 方法A + * @param func 方法B + */ +export declare type _afterFunc = (sFunc: Function, func: Function) => Function; \ No newline at end of file diff --git a/typescript/core/func/number.ts b/typescript/core/func/number.ts new file mode 100644 index 000000000..ae94252c7 --- /dev/null +++ b/typescript/core/func/number.ts @@ -0,0 +1,32 @@ + +/** + * 加法函数,用来得到精确的加法结果 + * @param {Number} num 被加数 + * @param {Number} arg 加数 + * @return {Number} 两个数字相加后的结果 + */ +export declare type _add = (num: number, arg: number) => number; + +/** + * 减法函数,用来得到精确的减法结果 + * @param {Number} num 被减数 + * @param {Number} arg 减数 + * @return {Number} 两个数字相减后的结果 + */ +export declare type _sub = (num: number, arg: number) => number; + +/** + * 乘法函数,用来得到精确的乘法结果 + * @param {Number} num 被乘数 + * @param {Number} arg 乘数 + * @return {Number} 两个数字相乘后的结果 + */ +export declare type _mul = (num: number, arg: number) => number; + +/** + * 除法函数,用来得到精确的除法结果 + * @param {Number} num 被除数 + * @param {Number} arg 除数 + * @return {Number} 两个数字相除后的结果 + */ +export declare type _div = (num: number, arg: number) => number; \ No newline at end of file diff --git a/typescript/index.ts b/typescript/index.ts index 92ff0b0c5..915679a2c 100644 --- a/typescript/index.ts +++ b/typescript/index.ts @@ -2,6 +2,8 @@ import { _addI18n, _i18nText } from "./core/i18n"; import { _OB } from "./core/ob"; import { _pushArray, _pushDistinct, _pushDistinctArray} from "./core/func/array"; import {_startWith, _allIndexOf, _appendQuery, _endWith, _getQuery, _perfectStart, _replaceAll} from "./core/func/string"; +import {_add, _sub, _mul, _div} from "./core/func/number"; +import {_afterFunc, _beforeFunc, _createDistinctName, _getSearchResult} from "./core/func/function"; export declare module BI { namespace i18n { @@ -22,4 +24,17 @@ export declare module BI { const replaceAll: _replaceAll; const perfectStart: _perfectStart; const allIndexOf: _allIndexOf; + + const add: _add; + const sub: _sub; + const mul: _mul; + const div: _div; + + const afterFunc: _afterFunc; + const beforeFunc: _beforeFunc; + + namespace Func { + const createDistinctName: _createDistinctName; + const getSearchResult: _getSearchResult; + } }