All Projects → Steveorevo → node-red-contrib-string

Steveorevo / node-red-contrib-string

Licence: other
Provides a string manipulation node with a chainable UI based on the concise and lightweight stringjs.com.

Programming Languages

HTML
75241 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to node-red-contrib-string

vbml
Way to check, match and resist.
Stars: ✭ 27 (+80%)
Mutual labels:  string, string-manipulation, string-matching
Litestringbuilder
Alternative to the System.Text.StringBuilder C# class.
Stars: ✭ 48 (+220%)
Mutual labels:  string, string-manipulation
Cracking The Coding Interview
Solutions for Cracking the Coding Interview - 6th Edition
Stars: ✭ 35 (+133.33%)
Mutual labels:  string, string-manipulation
Androidlibrary
Android library to reveal or obfuscate strings and assets at runtime
Stars: ✭ 162 (+980%)
Mutual labels:  string, string-manipulation
Portable Utf8
🉑 Portable UTF-8 library - performance optimized (unicode) string functions for php.
Stars: ✭ 405 (+2600%)
Mutual labels:  string, string-manipulation
Stringplus
Funny and minimal string library for C++ inspired by underscore.string
Stars: ✭ 7 (-53.33%)
Mutual labels:  string, string-manipulation
Strtk
C++ String Toolkit Library
Stars: ✭ 113 (+653.33%)
Mutual labels:  string, string-manipulation
normalize-text
📝 Provides a simple API to normalize texts, whitespaces, paragraphs & diacritics.
Stars: ✭ 54 (+260%)
Mutual labels:  string, string-manipulation
Str
A fast, solid and strong typed string manipulation library with multibyte support
Stars: ✭ 199 (+1226.67%)
Mutual labels:  string, string-manipulation
Util
A collection of useful utility functions
Stars: ✭ 201 (+1240%)
Mutual labels:  string, string-manipulation
Superstring.py
A fast and memory-optimized string library for heavy-text manipulation in Python
Stars: ✭ 231 (+1440%)
Mutual labels:  string, string-manipulation
Tiny Utf8
Unicode (UTF-8) capable std::string
Stars: ✭ 322 (+2046.67%)
Mutual labels:  string, string-manipulation
safe-string-interpolation
A type driven approach to string interpolation, aiming at consistent, secure, and only-human-readable logs and console outputs !
Stars: ✭ 14 (-6.67%)
Mutual labels:  string, string-manipulation
Mightystring
Making Ruby Strings Powerful
Stars: ✭ 28 (+86.67%)
Mutual labels:  string, string-manipulation
stringext
Extra string functions for OCaml
Stars: ✭ 20 (+33.33%)
Mutual labels:  string, string-manipulation
Strman Java
A Java 8 string manipulation library.
Stars: ✭ 1,362 (+8980%)
Mutual labels:  string, string-manipulation
strutil
Golang metrics for calculating string similarity and other string utility functions
Stars: ✭ 114 (+660%)
Mutual labels:  string, string-matching
split-on-first
Split a string on the first occurrence of a given separator
Stars: ✭ 68 (+353.33%)
Mutual labels:  string, string-manipulation
Voca rs
Voca_rs is the ultimate Rust string library inspired by Voca.js, string.py and Inflector, implemented as independent functions and on Foreign Types (String and str).
Stars: ✭ 167 (+1013.33%)
Mutual labels:  string, string-manipulation
common-words
Updated list of the 100 most common words in the English language. Useful for excluding these words from arrays.
Stars: ✭ 13 (-13.33%)
Mutual labels:  parse, string

node-red-contrib-string

Provides a node with native and extended chainable JavaScript string parsing and manipulation methods. The node is a high level wrapper for the concise and lightweight stringjs.com object and uses Node-RED's editor UI to create easy chaining. Additional string parsing functionality and compatibility have been added from the fork.

Applies string methods from a given context property and assigns the results optionally to the same or another context property. Methods can be chained by adding multiple methods sequentially and with parameters that are literal or from other context properties. The string object always passes along the msg object with (if any) changes applied.

By default, string "from" and "to" apply to the msg.payload property but may be set to any property of global, flow, or msg contexts.

Examples

Data Extraction - Get Technical FAX

Methods can be chained within the UI enabling complex and versatile parsing functionality. Here we can see how easy it is to extract the technical FAX phone number WhoIS information:

Node-RED Example

Consider the given WhoIS dump from a command line console (see image below). We will want to obtain the FAX number (outlined in the dashed yellow). The string node will extract the technical FAX phone number by first removing the header, followed by all data up to the phrase "Technical:". This ensures that we don't accidentally obtain a FAX number from another section. Lastly, the string node grabs the number from between the markers "Fax:" and a carriage return and displays the output in the Node-RED debug window.

WhoIS Commandline Dump

The extraction is performed using JavaScript's unique ability to chain actions on a given object such as the native String object or the popular jQuery component. This unique contribution to Node-RED furnishes a lightweight and enhanced version of string parsing functions. The visual representation in the first image could be coded by hand in JavaScript (after including all the dependencies) as:

console.log(
  msg.payload.getRightMost('%')
             .delLeftMost('Technical:')
             .between('FAX:', '\n')
);

Validate Phone Number

Furthermore, a single string node could have the properties set to perform data validation. In this simple example we'll perform some conditional checks to see if the phone number is numeric and furnish a friendly error message if it is not. Consider the following flow:

Validate Phone Number

Let's take a look at the string node titled "Verify Number" (see image below). The properties for the node have been configured to use the methods stripPunctuation and isNumeric which will result in a boolean true or false. Next, we convert the boolean to a string using toString. Lastly, we use the replaceAll methods to convert the only two boolean possibilities to the original number as found in property msg.payload or the informative error message "Error! Not a valid number.".

Verify Number Node

Using String in Node-RED Function Nodes

You can use the string object's methods inside Node-RED's function nodes. The dependency string.js for Node.js will have already been installed if you included the string node in your palette. This would allow you to use the parsing methods in JavaScript such as:

  // Always change the last word to World
  var greet = S("Hello Mars");
  msg.payload = greet.delRightMost(" ").append("World");

There are several easy ways to make the string object's methods available in your JavaScript function nodes:

Include String Node in Flow

A simple way is to just include the string node in your flow before the Node-RED function node. The string node will normally return a native JavaScript string datatype; however, if you use the setValue method with no value, a string.js object can be casted into a readily available property. In our example below we cast the object into msg.string.

Using String in JavaScript

The string object returns an instance of itself when using the setValue method. You can then write JavaScript to instantiate a copy of the string object.

var S = function(x) {
  return msg.string.setValue(x);
}
msg.payload = S("Hello World");

Enable Require in Node-RED

An alternative method to use the string object is to enable the require method by updating Node-RED's settings.js to enable Node.js' "require" ability.

node-red/node-red#41 (comment)

functionGlobalContext: {
    require:require,
    // os:require('os'),
    // octalbonescript:require('octalbonescript'),
    // jfive:require("johnny-five"),
    // j5board:require("johnny-five").Board({repl:false})
},

This will essentially give Node-RED's function node the ability to include any arbitrary Node.js library which you may or may not desire. Likewise, you could just update Node-RED's settings.js to just enable the string.js library by modifying the functionGlobalContext to read:

functionGlobalContext: {
    string:require("string")
},

Your Node-RED's function node could then instantiate a string object like so:

var S = global.get("string");
msg.payload = S("Hello World");

Installation

Run the following command in your Node-RED user directory (typically ~/.node-red):

npm install node-red-contrib-string

The string node will appear in the palette under the function group.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].