MapValues

Map the given values to the translated values. If given values: a,b,c, and translated: 1,2,3, then the input will return 1.

javascript · Common Scripts

Source

if (typeof args.input === 'object' && args.input !== null) {
    throw 'Input cannot be an object. Please provide a string or a number.';
}

var values = argToList(args.values);
var translated = argToList(args.translated);
var input = String(args.input).toLowerCase();

for (var i=0; i<values.length && i<translated.length; i++) {
    if (typeof values[i] === 'object' && values[i] !== null) {
        throw 'Values cannot contain objects. Please provide strings or numbers.';
    }
    if (input === String(values[i]).toLowerCase()) {
        return translated[i];
    }
}
return args.input;

README

Maps the given values to the translated values.

If given values: “a,b,c” and translated: 1,2,3 then input “a” will return a 1.

Script Data


Name Description
Script Type javascript
Tags Utility

Inputs


Argument Name Description
values The values that should be translated.
translated The translated values to be used to replace the values.
input The value to compare and replace.

Outputs


There are no outputs for this script.