@ezs/transformers
v1.4.7
Published
LODEX transformers statements for EZS
Readme
transformers
Ce plugin propose une série d'instructions spécifiques de transformation sur un seul champ d'un objet. Cette notion est utilisée dans lodex pour transformer les valeurs des colonnes à charger.
Chaque instruction possède le paramètre field.
Il s'agit du chemin vers le champ à transformer ou le chemin vers un nouveau champ.
Il est possible d'enchaîner les transformations sur un même champ :
[$PREFIX]
field = tag
with = <
[$SUFFIX]
field = tag
with = >Comme cette série d'instructions fonctionne uniqument sur un seul champ (et non sur la totalité comme les autres plugins),
elle génère en sortie un champ "technique" nommé $origin qui contient l'objet tel qu'il était avant d'appliquer un traitement.
Ce champ peut être facilement supprimé :
[$UPPERCASE]
field = title
[exchange]
value = omit('$origin')exemple
[
{ "id": 1, "title": "un" },
{ "id": 2, "title": "deux" },
{ "id": 3, "title": "trois" },
]Script:
[use]
plugin = transformers
[$UPPERCASE]
field = title
[$SUFFIX]
field = title
with = §
[$STRING]
field = id
[$PREFIX]
field = id
with = uri:/Output:
[
{ "id": "uri:/1", "title": "UN§" },
{ "id": "uri:/2", "title": "DEUX§" },
{ "id": "uri:/3", "title": "TROIS§" },
]installation
npm install @ezs/transformersusage
Table of Contents
- $ARRAY
- $BOOLEAN
- $CAPITALIZE
- $COLUMN
- $CONCAT
- $CONCAT_URI
- $DEFAULT
- $FORMAT
- $GET
- $JOIN
- $LOWERCASE
- $MAPPING
- $MASK
- $NUMBER
- $PARSE
- $PREFIX
- $REMOVE
- $REPLACE
- $REPLACE_REGEX
- $SELECT
- $SHIFT
- $SPLIT
- $STRING
- $SUFFIX
- $TRIM
- $TRUNCATE
- $TRUNCATE_WORDS
- $UNIQ
- $UPPERCASE
- $URLENCODE
- $VALUE
$ARRAY
transformer une chaîne de caractères en tableau avec un seul element
Exemple :
[$ARRAY]
field = keywords
[exchange]
value = omit('$origin')Entrée:
[{
"keywords": "un"
}, {
"keywords": "deux"
}]Sortie:
[{
"keywords": ["un"]
}, {
"keywords": ["deux"]
}]Parameters
datafeedfieldString field path to apply the transformation
Returns Object
$BOOLEAN
transformer une chaîne de caractères en booléen
Exemple :
[$BOOLEAN]
field = haveMoney
[exchange]
value = omit('$origin')Entrée:
[{
"name": "Chuck",
"haveMoney": 10000
}, {
"name": "Charlot",
"haveMoney": "yes"
}, {
"name": "Alan",
"haveMoney": 1
}]Sortie:
[{
"name": "Chuck",
"haveMoney": false
}, {
"name": "Charlot",
"haveMoney": true
}, {
"name": "Alan",
"haveMoney": true
}]Parameters
datafeedfieldString field path to apply the transformation
Returns Object
$CAPITALIZE
mettre le premier caractère en majuscule
Exemple :
[$CAPITALIZE]
field = titleParameters
datafeedfieldString? field path to apply the transformation
Returns Object
$COLUMN
prendre une donnée dans un champ (colonne d'un fichier tabulé)
Exemple :
[$COLUMN]
field = newTitle
column = oldTitleParameters
datafeedfieldString field path to apply the transformationcolumnString value to use during the transformation
Returns Object
$CONCAT
concaténer deux valeurs
Exemple :
[$CONCAT]
field = result
columns = part1
columns = part2Parameters
datafeedfieldString field path to get the result of the transformationcolumnsString field path to get value
Returns Object
$CONCAT_URI
composer un identifiant avec plusieurs champs
Exemple :
[$CONCAT_URI]
field = identifiant
column = nom
column = prenom
separator = -Parameters
datafeedfieldString field path to get the result of the transformationcolumnString field path to get dataseparatorString glue between each column
Returns Object
$DEFAULT
donner une valeur par défaut
Exemple :
[$DEFAULT]
field = title
alternative = not availableParameters
datafeedfieldString field path to apply the transformationalternativeString value to use if field does not exist
Returns Object
$FORMAT
appliquer un patron (template)
[$DEFAULT]
field = source
with = (%s:%s)Parameters
datafeedfieldString field path to get data source (must be an array)withString template string like sprintf
Returns Object
$GET
Récupère toutes les valeurs correspondant à un chemin (dot path)
Exemple :
[$GET]
field = output
path = inputParameters
datafeedfieldString field path to get the result of the transformationpathString field path to get value
Returns Object
$JOIN
Rassemble les valeurs d'un tableau en une chaîne de caractères
Exemple :
[$JOIN]
field = output
path = inputParameters
datafeedfieldString field path to apply the transformation (must be an array)separatorString glue between each field
Returns Object
$LOWERCASE
mettre en bas de casse (minuscules)
Exemple :
[$LOWERCASE]
field = titleParameters
datafeedfieldString field path to apply the transformation
Returns Object
$MAPPING
Opération permettant le remplacement à partir d'une table (équivalent à l'enchaînement de plusieurs opérations $REPLACE)
Exemple :
[$MAPPING]
field = keywords
list = "hello":"bonjour", "hi":"salut"Parameters
Returns Object
$MASK
S'assure que la valeur respecte une expression régulière
Exemple :
[$MASK]
field = title
with = ^[a-z]+$Parameters
Returns Object
$NUMBER
transformer une chaîne de caractères en nombre
Exemple :
[$NUMBER]
field = counterParameters
datafeedfieldString field path to apply the transformation
Returns Object
$PARSE
Analyser un chaine de caractère comme étant du JSON
Exemple :
[$PARSE]
field = jsonParameters
datafeedfieldString field path to apply the transformation
Returns Object
$PREFIX
préfixer la valeur avec une chaîne de caractères
Exemple :
[$PREFIX]
field = title
with = #Parameters
datafeedfieldString field path to apply the transformationwithString value to add at the begining of the field
Returns Object
$REMOVE
supprimer un élément ou une sous-chaîne
Exemple :
[$REMOVE]
field = title
the = .Parameters
Returns Object
$REPLACE
remplacer une chaîne par une autre
Exemple :
[$REPLACE]
field = title
searchValue = 1
replaceValue = unParameters
datafeedfieldString field path to apply the transformationsearchValueString value to searchreplaceValueString value to replace with
Returns Object
$REPLACE_REGEX
remplacer une chaîne par une autre via une exrpression régulière
Exemple :
[$REPLACE_REGEX]
field = title
searchValue = $hel\w+
replaceValue = bonjourParameters
datafeedfieldString field path to apply the transformationsearchValueString regex to searchreplaceValueString value to replace with
Returns Object
$SELECT
Prendre une valeur dans un objet à partir de son chemin (dot path)
Exemple :
[$SELECT]
field = title
path = enParameters
datafeedfieldString field path to get the result of the selectionpathString field path to get value
Returns Object
$SHIFT
décaler une valeur multiple (tableau ou chaîne de caractères)
Exemple :
[$SHIFT]
field = title
gap = 2Parameters
datafeedpathString field path to apply the transformationgapString how many items or characters to drop
Returns Object
$SPLIT
segmente une chaîne de caractères en tableau
Exemple :
[$SPLIT]
field = title
separator = |Parameters
datafeedfieldString field path to apply the transformationseparatorString value to use to split the field
Returns Object
$STRING
transforme la valeur en chaîne de caractères
Exemple :
[$STRING]
field = titleParameters
datafeedfieldString field path to apply the transformation
Returns Object
$SUFFIX
ajoute une chaîne de caractères à la fin d'une chaîne ou d'un tableau
Exemple :
[$SUFFIX]
field = title
with = !Parameters
datafeedfieldString field path to apply the transformationwithString value to add at the end of the field
Returns Object
$TRIM
enlève les espaces au début et à la fin d'une chaîne de caractères
Exemple :
[$TRIM]
field = titleParameters
datafeedfieldString field path to apply the transformation
Returns Object
$TRUNCATE
tronque, prend les premières valeurs d'un tableau, d'une chaîne
Exemple :
[$TRUNCATE]
field = title
gap = 25Parameters
datafeedfieldString field path to apply the transformationgapString how many items or characters to keep
Returns Object
$TRUNCATE_WORDS
Opération permettant la troncature par nombre de mots et non pas par nombre de caractères comme pour l'opération $TRUNCATE
Exemple :
[$TRUNCATE_WORDS]
field = title
gap = 10Parameters
Returns Object
$UNIQ
dédoublonne les valeurs (dans un tableau)
Exemple :
[$UNIQ]
field = titleParameters
datafeedfieldString field path to apply the transformation (must be an aarray)
Returns Object
$UPPERCASE
mettre la chaîne en majuscules
Exemple :
[$UPPERCASE]
field = titleParameters
datafeedfieldString field path to apply the transformation
Returns Object
$URLENCODE
encode une chaine comme dans une URL
Exemple :
[$URLENCODE]
field = urlParameters
datafeedfieldString field path to apply the transformation
Returns Object
$VALUE
Fixer une valeur
Exemple :
[$VALUE]
field = title
value = Hello worldParameters
Returns Object
