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/transformers
usage
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
data
feed
-
field
String 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
data
feed
-
field
String field path to apply the transformation
Returns Object
$CAPITALIZE
mettre le premier caractère en majuscule
Exemple :
[$CAPITALIZE]
field = title
Parameters
data
feed
-
field
String? 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 = oldTitle
Parameters
data
feed
-
field
String field path to apply the transformation -
column
String value to use during the transformation
Returns Object
$CONCAT
concaténer deux valeurs
Exemple :
[$CONCAT]
field = result
columns = part1
columns = part2
Parameters
data
feed
-
field
String field path to get the result of the transformation -
columns
String 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
data
feed
-
field
String field path to get the result of the transformation -
column
String field path to get data -
separator
String glue between each column
Returns Object
$DEFAULT
donner une valeur par défaut
Exemple :
[$DEFAULT]
field = title
alternative = not available
Parameters
data
feed
-
field
String field path to apply the transformation -
alternative
String value to use if field does not exist
Returns Object
$FORMAT
appliquer un patron (template)
[$DEFAULT]
field = source
with = (%s:%s)
Parameters
data
feed
-
field
String field path to get data source (must be an array) -
with
String template string like sprintf
Returns Object
$GET
Récupère toutes les valeurs correspondant à un chemin (dot path)
Exemple :
[$GET]
field = output
path = input
Parameters
data
feed
-
field
String field path to get the result of the transformation -
path
String 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 = input
Parameters
data
feed
-
field
String field path to apply the transformation (must be an array) -
separator
String glue between each field
Returns Object
$LOWERCASE
mettre en bas de casse (minuscules)
Exemple :
[$LOWERCASE]
field = title
Parameters
data
feed
-
field
String 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 = counter
Parameters
data
feed
-
field
String field path to apply the transformation
Returns Object
$PARSE
Analyser un chaine de caractère comme étant du JSON
Exemple :
[$PARSE]
field = json
Parameters
data
feed
-
field
String 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
data
feed
-
field
String field path to apply the transformation -
with
String 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 = un
Parameters
data
feed
-
field
String field path to apply the transformation -
searchValue
String value to search -
replaceValue
String 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 = bonjour
Parameters
data
feed
-
field
String field path to apply the transformation -
searchValue
String regex to search -
replaceValue
String value to replace with
Returns Object
$SELECT
Prendre une valeur dans un objet à partir de son chemin (dot path)
Exemple :
[$SELECT]
field = title
path = en
Parameters
data
feed
-
field
String field path to get the result of the selection -
path
String 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 = 2
Parameters
data
feed
-
path
String field path to apply the transformation -
gap
String 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
data
feed
-
field
String field path to apply the transformation -
separator
String value to use to split the field
Returns Object
$STRING
transforme la valeur en chaîne de caractères
Exemple :
[$STRING]
field = title
Parameters
data
feed
-
field
String 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
data
feed
-
field
String field path to apply the transformation -
with
String 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 = title
Parameters
data
feed
-
field
String 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 = 25
Parameters
data
feed
-
field
String field path to apply the transformation -
gap
String 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 = 10
Parameters
Returns Object
$UNIQ
dédoublonne les valeurs (dans un tableau)
Exemple :
[$UNIQ]
field = title
Parameters
data
feed
-
field
String field path to apply the transformation (must be an aarray)
Returns Object
$UPPERCASE
mettre la chaîne en majuscules
Exemple :
[$UPPERCASE]
field = title
Parameters
data
feed
-
field
String field path to apply the transformation
Returns Object
$URLENCODE
encode une chaine comme dans une URL
Exemple :
[$URLENCODE]
field = url
Parameters
data
feed
-
field
String field path to apply the transformation
Returns Object
$VALUE
Fixer une valeur
Exemple :
[$VALUE]
field = title
value = Hello world
Parameters
Returns Object