// 内置函数库 declare namespace nasl.util { /* 类型转换与格式化函数 */ /* 各基础数据类型之间转换 */ export function Convert(value: null): () => T; /** * 返回格式化的数字字符串 * @param doubleValue: 待格式化的数字 * @param digits: 小数位数 * @param omit: 是否省略小数位数为0的部分 * @param showGroups: 是否显示千分位分隔符 * @param fix: 前缀或后缀: prefix、suffix * @param unit: 前缀或后缀的内容 */ export function FormatNumber(doubleValue: Decimal | Long, digits: Long, omit: Boolean, showGroups: Boolean, fix: String, unit: String): String; /* 返回格式化的百分比 */ export function FormatPercent(doubleValue: Decimal | Long, digits: Long, omit: Boolean, showGroups: Boolean): String; /* 返回格式化日期时间字符串 */ /* @example nasl.util.FormatDateTime(nasl.util.CurrDateTime(), 'yyyy-MM-dd HH:mm:ss', 'global') */ export function FormatDateTime(dateTime: DateTime, formatter: String, timeZone: string): String; /* 返回格式化日期字符串 */ /* @example nasl.util.FormatDate(nasl.util.CurrDate(), 'yyyy-MM-dd') */ export function FormatDate(date: Date, formatter: String): String; /* 返回格式化时间字符串 */ /* @example nasl.util.FormatTime(nasl.util.CurrTime(), 'HH:mm:ss') */ export function FormatTime(time: Time, formatter: String): String; /* 字符串转换成其他类型 */ /* @example nasl.util.FromString('2021-01-01') */ export function FromString(value: String): T; /* 各类型转换成字符串 */ export function ToString(value: Any): String; /* 字符串函数 */ export function Length(str1: String): Long; export function Length(str1: Map): Long; export function Length(str1: List): Long; /* 用于查找字符串中指定字段所在位置,常用的场景包括字符串匹配、字符串替换、数据校验等 */ export function IndexOf(str: String, search: String, formIndex: Long, ignoreCase: Boolean): Long; export function Join(list: List, separator: String): String; export function LastIndexOf(str: String, search: String, ignoreCase: Boolean): Long; export function Replace(str: String, search: String, replace: String): String; export function Split(str: String, separator: String, trail: Boolean): List; export function SubString(str: String, start: Long, length: Long): String; export function ToLower(str1: String): String; export function ToUpper(str1: String): String; export function Trim(str1: String): String; /* 日期与时间函数 */ export function CurrDate(): Date; export function CurrDateTime(): DateTime; export function CurrTime(): Time; /** * 返回日期比较结果 * @param date1: 日期1 * @param date2: 日期2 * @param calcType: 计算类型。计算两个日期时间之间的差值,支持年数('y')、季度数('q')、月数('m')、周数('w')、天数('d')、小时数('h')、分钟数('m')、秒数('s')。默认为天数。 * @param isAbs: 是否返回绝对值,默认为 true * @returns 根据计算类型返回对应的差值 */ export function DateDiff(dateTime1: T, dateTime2: T, calcType: 'y' | 'q' | 'm' | 'w' | 'd' | 'h' | 'm' | 's', isAbs: Boolean): Long; /* 为指定日期时间调整增加(减少)时间 */ export function AlterDateTime(dateTime: T, option: 'Increase' | 'Decrease', amount: Long, unit: 'day' | 'week' | 'month' | 'quarter' | 'year'): T; /** * 按指定维度计算日期的序号。当输入为 DateTime 类型时,会把数据转到提供的时区的当地时间进行计算 * @param dateTime: 日期或日期时间 * @param metric: 计算维度,格式为'小日期单位-大日期单位'。日期单位包括:'year'、'quarter'、'month'、'week'、'day'。如设置 'week-year',则返回当前日期是所在年的第几周, 'day-week',则返回当前日期是所在周的第几天。 */ export function GetDateCount(dateTime: T, metric: String): Long; /** * 按“星期几”获取指定日期范围内的日子。当输入为 DateTime 类型时,会把数据转到提供的时区的当地时间进行计算。 * @param startDate: 开始日期/日期时间 * @param endDate: 结束日期/日期时间 * @param target: 目标星期几,1-7分别代表周一到周日 */ export function GetSpecificDaysOfWeek(startDate: T, endDate: T, target: List): List; // 列表(List)函数 export function ListAdd(list: List, item: K): void; export function ListAddAll(list: List, addList: List): Long; export function ListContains(list: List, item: K): Boolean; export function ListInsert(list: List, index: Long, item: K): void; export function ListDistinct(list: List): List; export function ListDistinctBy(list: List, by: List<{ items: Array<(elem: A) => any>; }>): List; export function ListFilter(list: List, by: (item: T) => Boolean): List; export function ListFind(list: List, by: (item: T) => Boolean): T; export function ListFindIndex(list: List, by: (item: T) => Boolean): Long; export function ListFlatten(list: List>): List; export function ListGroupBy(list: List, by: (elem: A) => K): Map>; export function ListHead(list: List): T; export function ListLast(list: List): T; export function ListMax(list: List): T; export function ListMin(list: List): T; export function ListReverse(list: List): List; export function ListSlice(list: List, start: Long, end: Long): List; /** * 对 list 进行排序 * @param list: 待排序的列表 * @param fns: 排序规则,可同时支持多个排序规则 * @returns 排序后的列表 * @example nasl.util.ListSort(list, (item) => ({ asc: true, by: item })); * @example nasl.util.ListSort(list, (item) => ({ asc: true, by: item.name }), (item) => ({ asc: false, by: item.age})); */ export function ListSort(list: List, ...fns: ((item: T) => { asc: Boolean, by: Boolean | Long | Decimal | String | Date | Time | DateTime; })[]): List; export function ListSum(list: List): T; export function ListToMap(map: List, byKey: (elem: T) => K, byVal: (elem: T) => V): Map; export function ListTransform(list: List, by: (elem: T0) => T): List; export function ListGet(list: List, index: Long): T; export function ListRemove(list: List, item: K): void; export function ListRemoveAt(list: List, index: Long): T; export function ListSet(list: List, index: Long, item: K): T; /* 生成指定范围和步长的整数列表,参数 start、end、step 需为整数 */ export function ListRange(start: Long, end: Long, step: Long): List; /* 生成指定长度的重复元素列表 */ export function ListRepeat(item: T, length: Long): List; /* 映射(Map)函数 */ export function MapContains(map: Map, key: K): Boolean; export function MapGet(map: Map, key: K): V; export function MapPut(map: Map, key: K, value: V): void; export function MapKeys(map: Map): List; export function MapRemove(map: Map, key: K): void; export function MapValues(map: Map): List; /* 枚举函数。项目中的枚举类型均定义在 app.enums 中 */ /* 返回枚举value和text的List集合 */ /* @example nasl.util.EnumToList() */ export function EnumToList(): List<{ text: String, value: String; }>; /* 返回枚举指定value的标题字符串 */ export function EnumItemToText(value: Enums): String; /* 数学函数 */ /** * 整数/小数 操作 * @param mode: 'HalfUp' | 'TowardsZero' | 'TowardsInfinity' === '四舍五入' | '截断、向零取整,如 -2.6 取整为 -2' | '进位、向正负无穷取整,如 -1.1 取整为 -2' */ export function Round(value: Decimal, mode: 'HalfUp' | 'TowardsZero' | 'TowardsInfinity'): Long; export function Ceil(value: Decimal): Integer; export function Floor(value: Decimal): Integer; export function Trunc(value: Decimal): Integer; export function TruncDivide(left: Decimal, right: Decimal): Integer; export function Abs(value: Integer): Integer; export function Abs(value: Decimal): Decimal; export function Pow(base: Decimal, exponent: Decimal): Decimal; export function Sqrt(value: Decimal): Decimal; export function Cbrt(value: Decimal): Decimal; /* 返回指定数字的自然对数 */ export function Log(value: Decimal): Decimal; export function PadStart(str: String, targetLength: String, fillStr = " "): String; export function PadEnd(str: String, targetLength: String, fillStr = " "): String; export function TrimStart(str: String): String; export function TrimEnd(str: String): String; /* RandomInt 生成的数字为整数,如果需要指定位数的随机数,需要在数字前按照位数要求补 0 */ export function RandomInt(start: Long, end: Long): Long; // 其他函数 /** * (修改原数据)清除复杂对象中每个属性的数据(若输入是单个基础类型如 Integer 的值,则不做处理) * @param struct 待清除的数据 * @param mode: 'deep': '保留层次结构,仅清除对象最深层的叶子结点(全为基本类型),将其设置为 null' | 'shallow': 不保留对象的层级结构,清理后的对象仅有第一层结构,值全部为 null。 */ export function Clear(struct: T, mode: 'deep' | 'shallow' = 'deep'): T; export function Clone(struct: T): T; /* 判断参数是否为有效值,null、空字符串、纯空格、长度为0的集合均不被视为有效值,传入多个参数时,判断是否全部都是有效值 */ export function HasValue(...args: Any[]): Boolean; // New 系列函数使用 /** * 生成新的列表,T 类型必填 * @example const variable1 = nasl.util.NewList([true, false, 1]) */ export function NewList(args: T[]): List; /** * 生成新的映射,K、T 类型必填 * @example const variable1 = nasl.util.NewMap({'123': 456}) */ export function NewMap(args: any): Map; /** * 生成新的数据实体,T 类型必填 * class Entity1 { id: Long; property1: String; property2: String;} * @example const variable1 = nasl.util.NewEntity({id: 123, property1: '123', property2: '456'}) */ export function NewEntity(arg: T): T; /** * 生成新的结构体,T 类型必填 * class Structure1 { id: Long; property1: String; property2: String;} * @example const variable1 = nasl.util.NewStructure({id: 123, property1: '123', property2: '456'}) */ export function NewStructure(arg: T): T; /** * 生成新的匿名结构体, 无需定义类型 * @example const variable1 = nasl.util.NewAnonymousStructure({property1: '123', property2: '456'}) */ export function NewAnonymousStructure(arg: Any): Any; /** * 输出日志 * @example nasl.util.consoleLog('输出日志'); */ export function consoleLog(arg: Any): void; export function jsonSerialize(arg: Any): String; /** * JSON 反序列化, T 为返回值类型,必填 * @example nasl.util.jsonDeserialize(variable1); */ export function jsonDeserialize(arg: String): T; }