From 88806f814470ce660daabdb69b2a916b1d465565 Mon Sep 17 00:00:00 2001 From: alan Date: Tue, 9 Jul 2019 11:52:20 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=B0=83=E6=95=B4=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E5=BD=A2=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typescript/core/func/array.ts | 9 ++- typescript/core/func/date.ts | 108 +++++++++++++++++++++++++++++++ typescript/core/func/function.ts | 10 ++- typescript/core/func/index.ts | 10 +++ typescript/core/func/number.ts | 10 ++- typescript/core/func/string.ts | 11 ++++ typescript/core/i18n.ts | 5 ++ typescript/index.ts | 44 ++----------- 8 files changed, 166 insertions(+), 41 deletions(-) create mode 100644 typescript/core/func/date.ts create mode 100644 typescript/core/func/index.ts diff --git a/typescript/core/func/array.ts b/typescript/core/func/array.ts index c69fa3ccb..a2e963a32 100644 --- a/typescript/core/func/array.ts +++ b/typescript/core/func/array.ts @@ -2,4 +2,11 @@ export declare type _pushArray = (sArray: any[], array: any[]) => void; export declare type _pushDistinct = (sArray: any[], obj: any) => void; -export declare type _pushDistinctArray = (sArray: any[], array: any[]) => void; \ No newline at end of file +export declare type _pushDistinctArray = (sArray: any[], array: any[]) => void; + +declare type _array = { + pushArray: _pushArray; + pushDistinct: _pushDistinct; + pushDistinctArray: _pushDistinctArray; +} +export default _array; \ No newline at end of file diff --git a/typescript/core/func/date.ts b/typescript/core/func/date.ts new file mode 100644 index 000000000..3efd887ba --- /dev/null +++ b/typescript/core/func/date.ts @@ -0,0 +1,108 @@ +export declare type _Date = { + SECOND: number; + MINUTE: number; + HOUR: number; + DAY: number; + WEEK: number; + _DN: string[]; + _SDN: string[]; + _FD: number; + _MN: string[]; + _SMN: number[]; + _QN: string[]; + _MD: number[]; + _OFFSET: number[]; +} +/** + * 获取时区 + */ +export declare type _getTimezone = (date: Date) => string; + +/** + * 获取指定月共有多少天 + */ +export declare type _getMonthDays = (date: Date, month: number) => string; + +/** + * 获取指定月的最后一天 + */ +export declare type _getLastDateOfMonth = (data: Date) => Date; + +/** + * 获取指定时间距离当年已经过了多少天 + */ +export declare type _getDayOfYear = (data: Date) => number; + +/** + * 获取指定时间距离当年已经过了多少周 + */ +export declare type _getWeekNumber = (data: Date) => number; + +/** + * 获取指定时间的所处季度 + */ +export declare type _getQuarter = (date: Date) => number; + +/** + * 离当前时间多少天的时间 + */ +export declare type _getOffsetDate = (date: Date, offset: number) => Date; + +/** + * 离当前时间多少天季度的时间 + */ +export declare type _getOffsetQuarter = (date: Date, n: number) => Date; + +/** + * 得到本季度的起始月份 + */ +export declare type _getQuarterStartMonth = (date: Date) => number; + +/** + * 获得本季度的起始日期 + */ +export declare type _getQuarterStartDate = (date: Date) => number; + +/** + * 获取本季度的其实日期 + */ +export declare type _getQuarterEndDate = (date: Date) => number; + +/** + * 指定日期n个月之前或之后的日期 + */ +export declare type _getOffsetMonth = (date: Date, n: number) => Date; + +/** + * 获取本周的起始日期 + */ +export declare type _getWeekStartDate = (date: Date) => Date; + +/** + * 获取本周的结束日期 + */ +export declare type _getWeekEndDate = (date: Date) => Date; + +/** + * 格式化打印日期 + */ +export declare type _print = (date: Date, str: string) => string; + +declare type _date = { + getTimezone: _getTimezone; + getMonthDays: _getMonthDays; + getLastDateOfMonth: _getLastDateOfMonth; + getDayOfYear: _getDayOfYear; + getWeekNumber: _getWeekNumber; + getQuarter: _getQuarter; + getOffsetDate: _getOffsetDate; + getOffsetQuarter: _getOffsetQuarter; + getQuarterStartMonth: _getQuarterStartMonth; + getQuarterStartDate: _getQuarterStartDate; + getQuarterEndDate: _getQuarterEndDate; + getOffsetMonth: _getOffsetMonth; + getWeekStartDate: _getWeekStartDate; + getWeekEndDate: _getWeekEndDate; + print: _print; +} +export default _date; \ No newline at end of file diff --git a/typescript/core/func/function.ts b/typescript/core/func/function.ts index b2c34c106..8aed27b42 100644 --- a/typescript/core/func/function.ts +++ b/typescript/core/func/function.ts @@ -26,4 +26,12 @@ export declare type _beforeFunc = (sFunc: Function, func: Function) => Function; * @param sFunc 方法A * @param func 方法B */ -export declare type _afterFunc = (sFunc: Function, func: Function) => Function; \ No newline at end of file +export declare type _afterFunc = (sFunc: Function, func: Function) => Function; + +declare type _function = { + createDistinctName: _createDistinctName; + getSearchResult: _getSearchResult; + beforeFunc: _beforeFunc; + afterFunc: _afterFunc; +} +export default _function; \ No newline at end of file diff --git a/typescript/core/func/index.ts b/typescript/core/func/index.ts new file mode 100644 index 000000000..573f48465 --- /dev/null +++ b/typescript/core/func/index.ts @@ -0,0 +1,10 @@ +import _array from "./array"; +import _string from "./string"; +import _number from "./number"; +import _function from "./function"; +import _date, {_Date} from "./date"; + +interface _func extends _array, _string, _number, _function { + Date: _Date; +} +export default _func; \ No newline at end of file diff --git a/typescript/core/func/number.ts b/typescript/core/func/number.ts index ae94252c7..185f29861 100644 --- a/typescript/core/func/number.ts +++ b/typescript/core/func/number.ts @@ -29,4 +29,12 @@ export declare type _mul = (num: number, arg: number) => number; * @param {Number} arg 除数 * @return {Number} 两个数字相除后的结果 */ -export declare type _div = (num: number, arg: number) => number; \ No newline at end of file +export declare type _div = (num: number, arg: number) => number; + +declare type _number = { + add: _add; + sub: _sub; + mul: _mul; + div: _div; +} +export default _number \ No newline at end of file diff --git a/typescript/core/func/string.ts b/typescript/core/func/string.ts index b8d8f3074..2e2c5e1aa 100644 --- a/typescript/core/func/string.ts +++ b/typescript/core/func/string.ts @@ -54,3 +54,14 @@ export declare type _perfectStart = (str: string, start: string) => string; * @return {Number[]} 子字符串在父字符串中出现的所有位置组成的数组 */ export declare type _allIndexOf = (str: string, sub: string) => number[]; + +declare type _string = { + startWith: _startWith; + endWith: _endWith; + getQuery: _getQuery; + appendQuery: _appendQuery; + replaceAll: _replaceAll; + perfectStart: _perfectStart; + allIndexOf: _allIndexOf; +} +export default _string \ No newline at end of file diff --git a/typescript/core/i18n.ts b/typescript/core/i18n.ts index c372dea74..4122508f1 100644 --- a/typescript/core/i18n.ts +++ b/typescript/core/i18n.ts @@ -1,3 +1,8 @@ export declare type _addI18n = (v: string) => string; export declare type _i18nText = (key: string) => string; + +export declare type _i18n = { + addI18n: _addI18n; + i18nText: _i18nText; +} \ No newline at end of file diff --git a/typescript/index.ts b/typescript/index.ts index 915679a2c..63b9a5c9e 100644 --- a/typescript/index.ts +++ b/typescript/index.ts @@ -1,40 +1,8 @@ -import { _addI18n, _i18nText } from "./core/i18n"; +import { _i18n } 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"; +import _func from "./core/func"; -export declare module BI { - namespace i18n { - const addI18n: _addI18n; - const i18nText: _i18nText; - } - - const OB: _OB; - - const pushArray: _pushArray; - const pushDistinct: _pushDistinct; - const pushDistinctArray: _pushDistinctArray; - - const startWith: _startWith; - const endWith: _endWith; - const getQuery: _getQuery; - const appendQuery: _appendQuery; - 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; - } -} +export interface BI extends _func { + i18n: _i18n; + OB: _OB; +} \ No newline at end of file