src/reference-variables.js
/**
 * Wait for some Reference Variables.
 *
 * Last argument is a callback function invoke when all Reference Variables are
 * available.
 *
 * If argument (except callback) is a single string, invoke callback with the
 * target RefVar. If it's a string object, invoke callback with the object with
 * same keys filled with RefVars. If argument is a string array or more than one
 * arguments are passed, invoke callback with the array filled with RefVars in
 * corresponding order.
 *
 * downode use Reference Path to reference other rules result. You can refer a
 * specified Rule result using Reference Path, but you can't refer a whole Page
 * Rule data, and refer a whole list data (use [index] to get the corresponding
 * item)
 *
 * NOTE:
 * - If the Rule Path name you refer to starts with `.`, use `\.` to escape.
 * (you probably need string `\\.` to get `\.`)
 * - If the Rule Path name you refer to ends with `[number]`, use `[number\]` to
 * escap. (you probably need string `[number\\]` to get `[number\]`)
 * - If the Rule Path name you refer to contains `/`, use `\/` to escape. (you
 * probably need string `\\/` to get `\/`)
 *
 * @param {any[]} args
 * @return {ReferenceVariableWaiter}
 */
Wait for some Reference Variables.
Last argument is a callback function invoke when all Reference Variables are
available.

If argument (except callback) is a single string, invoke callback with the
target RefVar. If it's a string object, invoke callback with the object with
same keys filled with RefVars. If argument is a string array or more than one
arguments are passed, invoke callback with the array filled with RefVars in
corresponding order.

downode use Reference Path to reference other rules result. You can refer a
specified Rule result using Reference Path, but you can't refer a whole Page
Rule data, and refer a whole list data (use [index] to get the corresponding
item)

- If the Rule Path name you refer to starts with `.`, use `\.` to escape.

@param {any[]} args
@return {ReferenceVariableWaiter}
Wait for some Reference Variables . Last argument is a callback function invoke when all Reference Variables are available . If argument ( except callback ) is a single string invoke callback with the target RefVar . If it ' s a string object invoke callback with the object with same keys filled with RefVars . If argument is a string array or more than one arguments are passed invoke callback with the array filled with RefVars in corresponding order . downode use Reference Path to reference other rules result . You can refer a specified Rule result using Reference Path but you can ' t refer a whole Page Rule data and refer a whole list data ( use [ index ] to get the corresponding item ) - If the Rule Path name you refer to starts with ` . ` use ` \ . ` to escape . @param { any [] } args @return { ReferenceVariableWaiter }
function waitFor(...args) {
	const callback = args.pop();
	ensureValueIsCallable(['last argument', callback]);
	if (args.length === 0) {
		return new ReferenceVariableWaiter(callback);
	}
	if (args.length === 1) {
		const firstArg = args[0];
		if (Array.isArray(firstArg)) {
			firstArg.map((arg, i) => [`firstArgument[${i}]`, arg]).forEach(ensureValueIsNonEmptyString);
		} else if (isPlainObject(firstArg)) {
			ensureValueIsNonEmptyObject([`first argument (for Reference Paths)`, firstArg]);
			for (const [key, value] of Object.entries(firstArg)) {
				ensureValueIsNonEmptyString([`firstArgument["${key}"]`, value]);
			}
		} else if (isString(firstArg)) {
			ensureValueIsNonEmptyString([`first argument (for Reference Paths)`, firstArg]);
		} else {
			throw new TypeError(`expect first argument (for Reference Path) to be a string array or string object`);
		}
		return new ReferenceVariableWaiter(callback, firstArg);
	}
	args.map((arg, i) => [`No.${i + 1} argument (for Reference Path)`, arg]).forEach(ensureValueIsNonEmptyString);
	return new ReferenceVariableWaiter(callback, args);
}
function waitFor ( ... args ) { const callback = args . pop ( ) ; ensureValueIsCallable ( [ 'last argument' , callback ] ) ; if ( args . length === 0 ) { return new ReferenceVariableWaiter ( callback ) ; } if ( args . length === 1 ) { const firstArg = args [ 0 ] ; if ( Array . isArray ( firstArg ) ) { firstArg . map ( ( arg , i ) => [ ` ${ i } ` , arg ] ) . forEach ( ensureValueIsNonEmptyString ) ; } else if ( isPlainObject ( firstArg ) ) { ensureValueIsNonEmptyObject ( [ ` ` , firstArg ] ) ; for ( const [ key , value ] of Object . entries ( firstArg ) ) { ensureValueIsNonEmptyString ( [ ` ${ key } ` , value ] ) ; } } else if ( isString ( firstArg ) ) { ensureValueIsNonEmptyString ( [ ` ` , firstArg ] ) ; } else { throw new TypeError ( ` ` ) ; } return new ReferenceVariableWaiter ( callback , firstArg ) ; } args . map ( ( arg , i ) => [ ` ${ i + 1 } ` , arg ] ) . forEach ( ensureValueIsNonEmptyString ) ; return new ReferenceVariableWaiter ( callback , args ) ; }
Wait for some Reference Variables.
Wait for some Reference Variables .