diff --git a/typescript/core/func/string.ts b/typescript/core/func/string.ts new file mode 100644 index 000000000..b8d8f3074 --- /dev/null +++ b/typescript/core/func/string.ts @@ -0,0 +1,56 @@ +/** + * 判断字符串是否已指定的字符串开始 + * @param str source字符串 + * @param {String} startTag 指定的开始字符串 + * @return {Boolean} 如果字符串以指定字符串开始则返回true,否则返回false + */ +export declare type _startWith = (str: string, startTag: string) => boolean; + +/** + * 判断字符串是否以指定的字符串结束 + * @param str source字符串 + * @param {String} endTag 指定的字符串 + * @return {Boolean} 如果字符串以指定字符串结束则返回true,否则返回false + */ +export declare type _endWith = (str: string, endTag: string) => boolean; + +/** + * 获取url中指定名字的参数 + * @param str source字符串 + * @param {String} name 参数的名字 + * @return {String} 参数的值 + */ +export declare type _getQuery = (str: string, name: string) => string|null; + +/** + * 给url加上给定的参数 + * @param str source字符串 + * @param {Object} paras 参数对象,是一个键值对对象 + * @return {String} 添加了给定参数的url + */ +export declare type _appendQuery = (str: string, paras: {[key: string]: string|number}) => string; + +/** + * 将所有符合第一个字符串所表示的字符串替换成为第二个字符串 + * @param str source字符串 + * @param {String} s1 要替换的字符串的正则表达式 + * @param {String} s2 替换的结果字符串 + * @returns {String} 替换后的字符串 + */ +export declare type _replaceAll = (str: string, s1: string, s2: string) => string; + +/** + * 总是让字符串以指定的字符开头 + * @param str source字符串 + * @param {String} start 指定的字符 + * @returns {String} 以指定字符开头的字符串 + */ +export declare type _perfectStart = (str: string, start: string) => string; + +/** + * 获取字符串中某字符串的所有项位置数组 + * @param str source字符串 + * @param {String} sub 子字符串 + * @return {Number[]} 子字符串在父字符串中出现的所有位置组成的数组 + */ +export declare type _allIndexOf = (str: string, sub: string) => number[]; diff --git a/typescript/index.ts b/typescript/index.ts index 95723ce61..92ff0b0c5 100644 --- a/typescript/index.ts +++ b/typescript/index.ts @@ -1,6 +1,7 @@ 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"; export declare module BI { namespace i18n { @@ -13,4 +14,12 @@ export declare module BI { 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; }