mirror of
https://github.com/fluxscape/fluxscape.git
synced 2026-01-12 07:12:54 +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:
76
packages/noodl-runtime/src/nodes/std-library/substring.js
Normal file
76
packages/noodl-runtime/src/nodes/std-library/substring.js
Normal file
@@ -0,0 +1,76 @@
|
||||
'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
|
||||
};
|
||||
Reference in New Issue
Block a user