{"id":13800539,"url":"https://github.com/steveorevo/node-red-contrib-string","last_synced_at":"2025-06-22T13:13:25.247Z","repository":{"id":90094274,"uuid":"105502706","full_name":"Steveorevo/node-red-contrib-string","owner":"Steveorevo","description":"Provides a string manipulation node with a chainable UI based on the concise and lightweight stringjs.com.","archived":false,"fork":false,"pushed_at":"2023-02-10T00:41:20.000Z","size":361,"stargazers_count":23,"open_issues_count":4,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-18T19:03:07.528Z","etag":null,"topics":["parse","string","string-manipulation","string-matching"],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Steveorevo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-10-02T06:03:12.000Z","updated_at":"2024-11-24T16:57:17.000Z","dependencies_parsed_at":"2023-05-22T19:30:29.201Z","dependency_job_id":null,"html_url":"https://github.com/Steveorevo/node-red-contrib-string","commit_stats":{"total_commits":23,"total_committers":1,"mean_commits":23.0,"dds":0.0,"last_synced_commit":"d0b2119af0478a8a34df35428f098ec29ec9f0a7"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Steveorevo/node-red-contrib-string","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Steveorevo%2Fnode-red-contrib-string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Steveorevo%2Fnode-red-contrib-string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Steveorevo%2Fnode-red-contrib-string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Steveorevo%2Fnode-red-contrib-string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Steveorevo","download_url":"https://codeload.github.com/Steveorevo/node-red-contrib-string/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Steveorevo%2Fnode-red-contrib-string/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261297113,"owners_count":23137229,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["parse","string","string-manipulation","string-matching"],"created_at":"2024-08-04T00:01:13.547Z","updated_at":"2025-06-22T13:13:20.229Z","avatar_url":"https://github.com/Steveorevo.png","language":"HTML","readme":"# node-red-contrib-string\nProvides a node with native and extended chainable JavaScript string parsing\nand manipulation methods. The node is a high level wrapper for the concise and\nlightweight [stringjs.com](https://web.archive.org/web/20171201072159/http://stringjs.com/) object and uses Node-RED's editor UI to create easy\nchaining. Additional string parsing functionality and compatibility have been\nadded from the [fork](https://github.com/Steveorevo/string.js).\n\nApplies string methods from a given context property and assigns the results\noptionally to the same or another context property. Methods can be chained by\nadding multiple methods sequentially and with parameters that are literal or\nfrom other context properties. The string object always passes along the msg\nobject with (if any) changes applied.\n\nBy default, string \"from\" and \"to\" apply to the `msg.payload` property but may\nbe set to any property of `global`, `flow`, or `msg` contexts.\n\n## Examples\n\n#### Data Extraction - Get Technical FAX\nMethods can be chained within the UI enabling complex and versatile parsing\nfunctionality. Here we can see how easy it is to extract the technical FAX phone\nnumber WhoIS information:\n\n![Node-RED Example](/string/demo/parsed-whois.png?raw=true \"Parse WhoIS for Technical FAX\")\n\nConsider the given WhoIS dump from a command line console (see image below).\nWe will want to obtain the FAX number (outlined in the dashed yellow). The string\nnode will extract the technical FAX phone number by first removing the header,\nfollowed by all data up to the phrase \"Technical:\". This ensures that we don't\naccidentally obtain a FAX number from another section. Lastly, the string node\ngrabs the number from between the markers \"Fax:\" and a carriage return and\ndisplays the output in the Node-RED debug window.\n\n![WhoIS Commandline Dump](/string/demo/technical-fax.png?raw=true \"Raw Commandline Dump from WhoIS\")\n\nThe extraction is performed using JavaScript's unique ability to chain actions on\na given object such as the native String object or the popular jQuery component.\nThis unique contribution to Node-RED furnishes a lightweight and enhanced version\nof string parsing functions. The visual representation in the first image could be\ncoded by hand in JavaScript (after including all the dependencies) as:\n```\nconsole.log(\n  msg.payload.getRightMost('%')\n             .delLeftMost('Technical:')\n             .between('FAX:', '\\n')\n);\n```\n\n#### Validate Phone Number\nFurthermore, a single string node could have the properties set to perform data\nvalidation. In this simple example we'll perform some conditional checks to\nsee if the phone number is numeric and furnish a friendly error message if it is\nnot. Consider the following flow:\n\n![Validate Phone Number](/string/demo/validate-phone.png?raw=true \"Validate Phone Number\")\n\nLet's take a look at the string node titled \"Verify Number\" (see image below).\nThe properties for the node have been configured to use the methods\n`stripPunctuation` and `isNumeric` which will result in a boolean true or false.\nNext, we convert the boolean to a string using `toString`. Lastly, we use the\n`replaceAll` methods to convert the only two boolean possibilities to the\noriginal number as found in property msg.payload or the informative error message\n _\"Error! Not a valid number.\"_.\n\n![Verify Number Node](/string/demo/validate-node-properties.png?raw=true \"Verify Number properties\")\n\n### Using String in Node-RED Function Nodes\nYou can use the string object's methods inside Node-RED's function nodes. The\ndependency string.js for Node.js will have already been installed if you included\nthe string node in your palette. This would allow you to use the parsing methods\nin JavaScript such as:\n\n```\n  // Always change the last word to World\n  var greet = S(\"Hello Mars\");\n  msg.payload = greet.delRightMost(\" \").append(\"World\");\n```\n\nThere are several easy ways to make the string object's methods available in your\nJavaScript function nodes:\n\n#### Include String Node in Flow\nA simple way is to just include the string node in your flow before the Node-RED\nfunction node. The string node will normally return a native JavaScript string\ndatatype; however, if you use the setValue method with no value, a string.js\nobject can be casted into a readily available property. In our example below we\ncast the object into `msg.string`.\n\n![Using String in JavaScript](/string/demo/use-in-function.png?raw=true \"Using String in JavaScript\")\n\nThe string object returns an instance of itself when using the setValue method.\nYou can then write JavaScript to instantiate a copy of the string object.\n\n```\nvar S = function(x) {\n  return msg.string.setValue(x);\n}\nmsg.payload = S(\"Hello World\");\n```\n\n#### Enable Require in Node-RED\nAn alternative method to use the string object is to enable the require method\nby updating Node-RED's settings.js to enable Node.js' \"require\" ability.\n\nhttps://github.com/node-red/node-red/issues/41#issuecomment-325554335\n\n```\nfunctionGlobalContext: {\n    require:require,\n    // os:require('os'),\n    // octalbonescript:require('octalbonescript'),\n    // jfive:require(\"johnny-five\"),\n    // j5board:require(\"johnny-five\").Board({repl:false})\n},\n```\nThis will essentially give Node-RED's function node the ability to include any\narbitrary Node.js library which you may or may not desire. Likewise, you could\njust update Node-RED's settings.js to just enable the string.js library by\nmodifying the functionGlobalContext to read:\n```\nfunctionGlobalContext: {\n    string:require(\"string\")\n},\n```\n\nYour Node-RED's function node could then instantiate a string object like so:\n```\nvar S = global.get(\"string\");\nmsg.payload = S(\"Hello World\");\n```\n\n## Installation\nRun the following command in your Node-RED user directory (typically ~/.node-red):\n\n    npm install node-red-contrib-string\n\nThe string node will appear in the palette under the function group.\n","funding_links":[],"categories":["Nodes"],"sub_categories":["Utility"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteveorevo%2Fnode-red-contrib-string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsteveorevo%2Fnode-red-contrib-string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteveorevo%2Fnode-red-contrib-string/lists"}