mirror of
https://github.com/fluxscape/fluxscape.git
synced 2026-01-11 23:02:55 +01:00
Initial commit
Co-Authored-By: Eric Tuvesson <eric.tuvesson@gmail.com> Co-Authored-By: mikaeltellhed <2311083+mikaeltellhed@users.noreply.github.com> Co-Authored-By: kotte <14197736+mrtamagotchi@users.noreply.github.com> Co-Authored-By: Anders Larsson <64838990+anders-topp@users.noreply.github.com> Co-Authored-By: Johan <4934465+joolsus@users.noreply.github.com> Co-Authored-By: Tore Knudsen <18231882+torekndsn@users.noreply.github.com> Co-Authored-By: victoratndl <99176179+victoratndl@users.noreply.github.com>
This commit is contained in:
94
packages/noodl-runtime/src/nodes/std-library/stringmapper.js
Normal file
94
packages/noodl-runtime/src/nodes/std-library/stringmapper.js
Normal file
@@ -0,0 +1,94 @@
|
||||
const StringMapperNode = {
|
||||
name: 'String Mapper',
|
||||
docs: 'https://docs.noodl.net/nodes/string-manipulation/string-mapper',
|
||||
category: 'Utilities',
|
||||
initialize: function () {
|
||||
this._internal.inputs = [];
|
||||
this._internal.mappings = [];
|
||||
},
|
||||
getInspectInfo() {
|
||||
return this._internal.mappedString;
|
||||
},
|
||||
numberedInputs: {
|
||||
input: {
|
||||
type: 'string',
|
||||
displayPrefix: 'Input',
|
||||
group: 'Inputs',
|
||||
index: 10,
|
||||
createSetter(index) {
|
||||
return function (value) {
|
||||
value = value === undefined ? '' : value.toString();
|
||||
this._internal.inputs[index] = value;
|
||||
this.scheduleMapping();
|
||||
};
|
||||
}
|
||||
},
|
||||
output: {
|
||||
type: 'string',
|
||||
displayPrefix: 'Mapping',
|
||||
index: 1001,
|
||||
group: 'Mappings',
|
||||
createSetter(index) {
|
||||
return function (value) {
|
||||
value = value === undefined ? '' : value.toString();
|
||||
this._internal.mappings[index] = value;
|
||||
this.scheduleMapping();
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
inputs: {
|
||||
inputString: {
|
||||
type: {
|
||||
name: 'string'
|
||||
},
|
||||
index: 1,
|
||||
displayName: 'Input String',
|
||||
set: function (value) {
|
||||
this._internal.currentInputString = value !== undefined ? value.toString() : undefined;
|
||||
this.scheduleMapping();
|
||||
}
|
||||
},
|
||||
defaultMapping: {
|
||||
type: 'string',
|
||||
displayName: 'Default',
|
||||
index: 1000,
|
||||
group: 'Mappings',
|
||||
set: function (value) {
|
||||
this._internal.defaultMapping = value;
|
||||
this.scheduleMapping();
|
||||
}
|
||||
}
|
||||
},
|
||||
outputs: {
|
||||
mappedString: {
|
||||
type: 'string',
|
||||
displayName: 'Mapped String',
|
||||
group: 'Value',
|
||||
getter: function () {
|
||||
return this._internal.mappedString;
|
||||
}
|
||||
}
|
||||
},
|
||||
prototypeExtensions: {
|
||||
doMapping: function () {
|
||||
this._internal.hasScheduledFetch = false;
|
||||
var idx = this._internal.inputs.indexOf(this._internal.currentInputString);
|
||||
if (idx !== -1) this._internal.mappedString = this._internal.mappings[idx];
|
||||
else this._internal.mappedString = this._internal.defaultMapping;
|
||||
|
||||
this.flagOutputDirty('mappedString');
|
||||
},
|
||||
scheduleMapping: function () {
|
||||
var internal = this._internal;
|
||||
if (!internal.hasScheduledFetch) {
|
||||
internal.hasScheduledFetch = true;
|
||||
this.scheduleAfterInputsHaveUpdated(this.doMapping.bind(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
node: StringMapperNode
|
||||
};
|
||||
Reference in New Issue
Block a user