mirror of
https://github.com/fluxscape/fluxscape.git
synced 2026-01-11 23:02:55 +01:00
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>
77 lines
1.8 KiB
JavaScript
77 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
const SubStringNode = {
|
|
name: 'Substring',
|
|
docs: 'https://docs.noodl.net/nodes/string-manipulation/substring',
|
|
category: 'String Manipulation',
|
|
initialize: function () {
|
|
var internal = this._internal;
|
|
internal.startIndex = 0;
|
|
internal.endIndex = -1;
|
|
internal.cachedResult = '';
|
|
internal.inputString = '';
|
|
internal.resultDirty = false;
|
|
},
|
|
inputs: {
|
|
start: {
|
|
type: 'number',
|
|
displayName: 'Start',
|
|
default: 0,
|
|
set: function (value) {
|
|
this._internal.startIndex = value;
|
|
this._internal.resultDirty = true;
|
|
this.flagOutputDirty('result');
|
|
}
|
|
},
|
|
end: {
|
|
type: 'number',
|
|
displayName: 'End',
|
|
default: 0,
|
|
set: function (value) {
|
|
this._internal.endIndex = value;
|
|
this._internal.resultDirty = true;
|
|
this.flagOutputDirty('result');
|
|
}
|
|
},
|
|
string: {
|
|
type: {
|
|
name: 'string'
|
|
},
|
|
displayName: 'String',
|
|
default: '',
|
|
set: function (value) {
|
|
value = value.toString();
|
|
this._internal.inputString = value;
|
|
this._internal.resultDirty = true;
|
|
this.flagOutputDirty('result');
|
|
}
|
|
}
|
|
},
|
|
outputs: {
|
|
result: {
|
|
type: 'string',
|
|
displayName: 'Result',
|
|
getter: function () {
|
|
var internal = this._internal;
|
|
|
|
if (internal.resultDirty) {
|
|
if (internal.endIndex === -1) {
|
|
internal.cachedResult = internal.inputString.substr(internal.startIndex);
|
|
} else {
|
|
internal.cachedResult = internal.inputString.substr(
|
|
internal.startIndex,
|
|
internal.endIndex - internal.startIndex
|
|
);
|
|
}
|
|
internal.resultDirty = false;
|
|
}
|
|
return internal.cachedResult;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
node: SubStringNode
|
|
};
|