@ezs/strings v1.0.5
@ezs/strings
Des intructions pour manipuler des chaînes de caratères.
installation
npm install @ezs/core
npm install @ezs/stringsÀ mettre au début du script:
[use]
plugin = stringsusage
Table of Contents
decode
Decodes a given string using a provided mapping, replacing strings that match values (to)in the mapping with their corresponding keys (from). Optionally, a prefix and suffix can be set (they are removed too from strings).
This statement is the reverse of encode.
Input:
[{
"id": "1",
"value": "Flow control based inffivesup MW wind turbine",
}, {
"id": "2",
"value": "Motion Characteristics of infonesupinfzerosup MW Superconducting Floating Offshore Wind Turbine",
}]Script:
[decode]
path = value
from = 1
to = one
from = 5
to = five
from = 0
to = zero
prefix = inf
suffix = supOutput:
[{
"id": "1",
"value": "Flow control based 5 MW wind turbine",
}, {
"id": "2",
"value": "Motion Characteristics of 10 MW Superconducting Floating Offshore Wind Turbine",
}]⚠ You must give as much
fromasto.
See encode.
Parameters
pathstring The path of the string to be decoded, within data.fromArray[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) An array of strings to replace with.toArray[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) An array of strings to be replaced.prefixstring A string to be removed from the beginning of each replaced substring. (optional, default"")suffixstring A string to be removed from the end of each replaced substring. (optional, default"")
encode
Encodes a given string using a provided mapping, replacing characters that match keys in the mapping with their corresponding values. Optionally, a prefix and suffix can be added to the final result.
Input:
[{
"id": "1",
"value": "Flow control based 5 MW wind turbine",
}, {
"id": "2",
"value": "Motion Characteristics of 10 MW Superconducting Floating Offshore Wind Turbine",
}]Script:
[encode]
path = value
from = 1
to = one
from = 5
to = five
from = 0
to = zero
prefix = inf
suffix = supOutput:
[{
"id": "1",
"value": "Flow control based inffivesup MW wind turbine",
}, {
"id": "2",
"value": "Motion Characteristics of infonesupinfzerosup MW Superconducting Floating Offshore Wind Turbine",
}]⚠ The replacements are made in the order of the
fromarray. This means that if 1 is replaced with 2, and next 2 replaced with 3, a 1 is eventually replaced with 3.⚠ You must give as much
fromasto.
See decode to invert the processus.
Parameters
pathstring The path of the string to be encoded, within data.fromArray[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) An array of strings to replace.toArray[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) An array of strings to replace with.prefixstring A string to be added to the beginning of each replaced substring. (optional, default"")suffixstring A string to be added to the end of each replaced substring. (optional, default"")
inflection
Take a String and inflect it with or more transformers from this list
pluralize, singularize, camelize, underscore, humanize, capitalize,
dasherize, titleize, demodulize, tableize, classify, foreign_key, ordinalize
Input:
{ "id": 1, "value": "all job" }Script:
[inflection]
path = value
transform = pluralize
transform = capitalize
transform = dasherizeOutput:
{ "id": 1, "value": "All-jobs" }📗 When the path is not given, the input data is considered as a string, allowing to apply
inflectionon a string stream.
see https://www.npmjs.com/package/inflection
Parameters
pathstring path of the field to segment (optional, default"")transformstring? name of a transformer
Returns Array[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)
sentences
Take a String and split it into an array of sentences.
Input:
{ "id": 1, "value": "First sentence? Second sentence. My name is Bond, J. Bond." }Output:
{ "id": 1, "value": ["First sentence?", "Second sentence.", "My name is Bond, J. Bond."] }📗 When the path is not given, the input data is considered as a string, allowing to apply
inflectionon a string stream.
Parameters
pathstring path of the field to segment (optional, default"")
Returns Array[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)