doc: 完善公式文档说明 (#11239)

This commit is contained in:
liaoxuezhi 2024-11-21 16:11:51 +08:00 committed by GitHub
parent d938e410a9
commit 6f41563f51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -679,7 +679,7 @@ export class Evaluator {
/** /**
* *
* *
* @example MAX(num1, num2, ...numN) * @example MAX(num1, num2, ...numN) or MAX([num1, num2, ...numN])
* @param {...number} num - * @param {...number} num -
* @namespace * @namespace
* *
@ -696,7 +696,7 @@ export class Evaluator {
/** /**
* *
* *
* @example MIN(num1, num2, ...numN) * @example MIN(num1, num2, ...numN) or MIN([num1, num2, ...numN])
* @param {...number} num - * @param {...number} num -
* @namespace * @namespace
* *
@ -713,7 +713,7 @@ export class Evaluator {
/** /**
* *
* *
* @example SUM(num1, num2, ...numN) * @example SUM(num1, num2, ...numN) or SUM([num1, num2, ...numN])
* @param {...number} num - * @param {...number} num -
* @namespace * @namespace
* *
@ -848,7 +848,7 @@ export class Evaluator {
/** /**
* *
* *
* @example AVG(num1, num2, ...numN) * @example AVG(num1, num2, ...numN) or AVG([num1, num2, ...numN])
* @param {...number} num - * @param {...number} num -
* @namespace * @namespace
* *
@ -1057,7 +1057,7 @@ export class Evaluator {
return base; return base;
} }
return Math.pow(base, exponent); return Math.pow(this.formatNumber(base), this.formatNumber(exponent));
} }
// 文本函数 // 文本函数
@ -1124,7 +1124,7 @@ export class Evaluator {
* @returns {number[]} * @returns {number[]}
*/ */
fnLENGTH(...args: any[]) { fnLENGTH(...args: any[]) {
return this.fnLEN.call(this, args); return this.fnLEN.apply(this, args);
} }
/** /**
@ -1150,7 +1150,7 @@ export class Evaluator {
* @returns {string} * @returns {string}
*/ */
fnCONCATENATE(...args: Array<any>) { fnCONCATENATE(...args: Array<any>) {
return args.join(''); return args.map(this.normalizeText).join('');
} }
/** /**
@ -1378,7 +1378,7 @@ export class Evaluator {
* @param {string} startString - * @param {string} startString -
* @namespace * @namespace
* *
* @returns {string} * @returns {boolean}
*/ */
fnSTARTSWITH(text: string, search: string) { fnSTARTSWITH(text: string, search: string) {
search = this.normalizeText(search); search = this.normalizeText(search);
@ -1398,7 +1398,7 @@ export class Evaluator {
* @param {string} endString - * @param {string} endString -
* @namespace * @namespace
* *
* @returns {string} * @returns {boolean}
*/ */
fnENDSWITH(text: string, search: string) { fnENDSWITH(text: string, search: string) {
search = this.normalizeText(search); search = this.normalizeText(search);
@ -1418,7 +1418,7 @@ export class Evaluator {
* @param {string} searchText - * @param {string} searchText -
* @namespace * @namespace
* *
* @returns {string} * @returns {boolean}
*/ */
fnCONTAINS(text: string, search: string) { fnCONTAINS(text: string, search: string) {
search = this.normalizeText(search); search = this.normalizeText(search);
@ -1501,13 +1501,17 @@ export class Evaluator {
/** /**
* *
* *
* `MID("amis.baidu.com", 6, 3)`
*
* `aid`
*
* @example MID(text, from, len) * @example MID(text, from, len)
* @param {string} text - * @param {string} text -
* @param {number} from - * @param {number} from -
* @param {number} len - * @param {number} len -
* @namespace * @namespace
* *
* @returns {number} * @returns {string}
*/ */
fnMID(text: string, from: number, len: number) { fnMID(text: string, from: number, len: number) {
text = this.normalizeText(text); text = this.normalizeText(text);
@ -1521,7 +1525,7 @@ export class Evaluator {
* *
* `/home/amis/a.json` * `/home/amis/a.json`
* *
* a.json` * `a.json`
* *
* @example BASENAME(text) * @example BASENAME(text)
* @param {string} text - * @param {string} text -
@ -1741,7 +1745,7 @@ export class Evaluator {
* @param {date} date * @param {date} date
* @param {string} unit 'day''month''year' `week` * @param {string} unit 'day''month''year' `week`
* @param {string} format * @param {string} format
* @returns {date} * @returns {date | string} , format
*/ */
fnSTARTOF(date: Date, unit?: any, format?: string) { fnSTARTOF(date: Date, unit?: any, format?: string) {
const md = moment(this.normalizeDate(date)).startOf(unit || 'day'); const md = moment(this.normalizeDate(date)).startOf(unit || 'day');
@ -1756,7 +1760,7 @@ export class Evaluator {
* @param {date} date * @param {date} date
* @param {string} unit 'day''month''year' `week` * @param {string} unit 'day''month''year' `week`
* @param {string} format * @param {string} format
* @returns {date} * @returns {date | string} , format
*/ */
fnENDOF(date: Date, unit?: any, format?: string) { fnENDOF(date: Date, unit?: any, format?: string) {
const md = moment(this.normalizeDate(date)).endOf(unit || 'day'); const md = moment(this.normalizeDate(date)).endOf(unit || 'day');
@ -2063,7 +2067,7 @@ export class Evaluator {
* @param {Array<any>} arr * @param {Array<any>} arr
* @namespace * @namespace
* @example COUNT(arr) * @example COUNT(arr)
* @returns {boolean} * @returns {number}
*/ */
fnCOUNT(value: any) { fnCOUNT(value: any) {
return Array.isArray(value) ? value.length : value ? 1 : 0; return Array.isArray(value) ? value.length : value ? 1 : 0;
@ -2072,11 +2076,17 @@ export class Evaluator {
/** /**
* 使 * 使
* *
*
*
*
*
* ARRAYMAP([1, 2, 3], item => item + 1) [2, 3, 4]
*
* @param {Array<any>} arr * @param {Array<any>} arr
* @param {Function<any>} iterator * @param {Function<any>} iterator
* @namespace * @namespace
* @example ARRAYMAP(arr, item => item) * @example ARRAYMAP(arr, item => item)
* @returns {boolean} * @returns {Array<any>}
*/ */
fnARRAYMAP(value: any, iterator: any) { fnARRAYMAP(value: any, iterator: any) {
if (!iterator || iterator.type !== 'anonymous_function') { if (!iterator || iterator.type !== 'anonymous_function') {
@ -2092,11 +2102,15 @@ export class Evaluator {
* 使 * 使
* false * false
* *
*
*
* ARRAYFILTER([1, 2, 3], item => item > 1) [2, 3]
*
* @param {Array<any>} arr * @param {Array<any>} arr
* @param {Function<any>} iterator * @param {Function<any>} iterator
* @namespace * @namespace
* @example ARRAYFILTER(arr, item => item) * @example ARRAYFILTER(arr, item => item)
* @returns {boolean} * @returns {Array<any>}
*/ */
fnARRAYFILTER(value: any, iterator: any) { fnARRAYFILTER(value: any, iterator: any) {
if (!iterator || iterator.type !== 'anonymous_function') { if (!iterator || iterator.type !== 'anonymous_function') {
@ -2259,7 +2273,7 @@ export class Evaluator {
* @param { String} separator * @param { String} separator
* @namespace * @namespace
* @example JOIN(arr, string) * @example JOIN(arr, string)
* @returns {String} * @returns {string}
*/ */
fnJOIN(arr: any[], separator = '') { fnJOIN(arr: any[], separator = '') {
if (Array.isArray(arr)) { if (Array.isArray(arr)) {
@ -2293,7 +2307,7 @@ export class Evaluator {
* *
* *
* *
* UNIQ([{a: '1'}, {b: '2'}, {a: '1'}] 'id') * UNIQ([{a: '1'}, {b: '2'}, {a: '1'}]) [{a: '1'}, {b: '2'}]
* *
* @param {Array<any>} arr * @param {Array<any>} arr
* @param {string} field * @param {string} field