Skip to content
Snippets Groups Projects
Select Git revision
  • 97c970370d43d875c3c4615888735298129172a8
  • master default protected
  • v1.23.2
  • v1.23.1
  • v1.23.0
  • v1.22.0
  • v1.21.1
  • v1.21.0
  • v1.20.3
  • v1.20.2
  • v1.20.1
  • v1.20.0
  • v1.19.4
  • v1.19.3
  • v1.19.2
  • v1.19.1
  • v1.19.0
  • v1.18.2
  • v1.18.1
  • v1.18.0
  • v1.17.0
  • v1.16.1
22 results

event-bus_test.go

Blame
  • transformer.mjs 17.87 KiB
    /**
     * Copyright schukai GmbH and contributors 2023. All Rights Reserved.
     * Node module: @schukai/monster
     * This file is licensed under the AGPLv3 License.
     * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
     */
    
    import { getLocaleOfDocument } from "../dom/locale.mjs";
    import { Base } from "../types/base.mjs";
    import { getGlobal, getGlobalObject } from "../types/global.mjs";
    import { ID } from "../types/id.mjs";
    import { isArray, isObject, isString, isPrimitive } from "../types/is.mjs";
    import {
    	getDocumentTranslations,
    	Translations,
    } from "../i18n/translations.mjs";
    import {
    	validateFunction,
    	validateInteger,
    	validateObject,
    	validatePrimitive,
    	validateString,
    	validateBoolean,
    } from "../types/validate.mjs";
    import { clone } from "../util/clone.mjs";
    import { Pathfinder } from "./pathfinder.mjs";
    
    export { Transformer };
    
    /**
     * The transformer class is a swiss army knife for manipulating values. especially in combination with the pipe, processing chains can be built up.
     *
     * A simple example is the conversion of all characters to lowercase. for this purpose the command `tolower` must be used.
     *
     * ```
     * let t = new Transformer('tolower').run('ABC'); // ↦ abc
     * ```
     *
     * @see {@link https://monsterjs.org/en/doc/#transformer|Monster Docs}
     *
     * @externalExample ../../example/data/transformer.mjs
     * @license AGPLv3
     * @since 1.5.0
     * @copyright schukai GmbH
     * @memberOf Monster.Data
     */
    class Transformer extends Base {
    	/**
    	 *
    	 * @param {string} definition
    	 */
    	constructor(definition) {
    		super();
    		this.args = disassemble(definition);
    		this.command = this.args.shift();
    		this.callbacks = new Map();
    	}
    
    	/**
    	 *
    	 * @param {string} name
    	 * @param {function} callback
    	 * @param {object} context
    	 * @returns {Transformer}
    	 * @throws {TypeError} value is not a string
    	 * @throws {TypeError} value is not a function
    	 */
    	setCallback(name, callback, context) {
    		validateString(name);
    		validateFunction(callback);