-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
102 changed files
with
2,232 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"presets": [ | ||
"@babel/preset-env" | ||
], | ||
"plugins": [ | ||
"@babel/plugin-syntax-dynamic-import", | ||
"@babel/plugin-syntax-import-meta", | ||
"@babel/plugin-proposal-class-properties", | ||
"@babel/plugin-proposal-json-strings" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*.tgz | ||
*.swp | ||
*.swo | ||
README.html | ||
node_modules | ||
coverage/ | ||
*.sw? | ||
lib | ||
benchmark | ||
.nyc_output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
" https://github.com/thinca/vim-localrc/blob/master/doc/localrc.txt | ||
set formatoptions+=tl | ||
set expandtab | ||
set tabstop=4 | ||
set softtabstop=4 | ||
set shiftwidth=4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
coverage/ | ||
bench/ | ||
examples/ | ||
test/ | ||
.nyc_output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"tabWidth": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# @ezs/transformers | ||
|
||
## Présentation | ||
|
||
Ce plugin est propose une série d'instructions permettant de transformer les objects JSON via les transformers de l'outil LODEX | ||
|
||
## installation | ||
|
||
```bash | ||
npm install @ezs/transformers | ||
``` | ||
|
||
## usage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "@ezs/transformers", | ||
"version": "1.0.0", | ||
"description": "LODEX transformers statements for EZS", | ||
"directories": { | ||
"test": "src" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Inist-CNRS/ezs.git" | ||
}, | ||
"keywords": [ | ||
"ezs" | ||
], | ||
"author": "Nicolas Thouvenin <[email protected]>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/Inist-CNRS/ezs/issues" | ||
}, | ||
"homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/transformers#readme", | ||
"dependencies": { | ||
}, | ||
"main": "./lib/index.js", | ||
"scripts": { | ||
"doc": "documentation readme src/* --markdown-toc-max-depth=2 --readme-file=../../docs/plugin-transformers.md --section=usage && cp ../../docs/plugin-transformers.md ./README.md", | ||
"lint": "eslint --ext=.js ./test/*.js ./src/*.js", | ||
"build": "babel --root-mode upward src --out-dir lib", | ||
"prepublish": "npm run build", | ||
"pretest": "npm run build", | ||
"preversion": "npm run doc" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"peerDependencies": { | ||
"@ezs/core": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import transformer from './operations/ARRAY'; | ||
import dollar from './dollar'; | ||
|
||
/** | ||
* transformer une chaîne de caractères en tableau avec un seul element | ||
* | ||
* @param {String} [path] field path to apply the transformation | ||
* @param {String} [value] value to use during the transformation | ||
* @returns {Object} | ||
*/ | ||
export default function $ARRAY(data, feed) { | ||
return dollar(this, data, feed, transformer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import transformer from './operations/AUTOGENERATE_URI'; | ||
import dollar from './dollar'; | ||
|
||
/** | ||
* générer automatiquement des identifiants | ||
* | ||
* @param {String} [path] field path to apply the transformation | ||
* @param {String} [value] value to use during the transformation | ||
* @returns {Object} | ||
*/ | ||
export default function $AUTOGENERATE_URI(data, feed) { | ||
return dollar(this, data, feed, transformer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import transformer from './operations/BOOLEAN'; | ||
import dollar from './dollar'; | ||
|
||
/** | ||
* transformer une chaîne de caractères en booléen | ||
* | ||
* @param {String} [path] field path to apply the transformation | ||
* @param {String} [value] value to use during the transformation | ||
* @returns {Object} | ||
*/ | ||
export default function $BOOLEAN(data, feed) { | ||
return dollar(this, data, feed, transformer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import transformer from './operations/CAPITALIZE'; | ||
import dollar from './dollar'; | ||
|
||
/** | ||
* mettre le premier caractère en majuscule | ||
* | ||
* @param {String} [path] field path to apply the transformation | ||
* @param {String} [value] value to use during the transformation | ||
* @returns {Object} | ||
*/ | ||
export default function $CAPITALIZE(data, feed) { | ||
return dollar(this, data, feed, transformer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import transformer from './operations/COLUMN'; | ||
import dollar from './dollar'; | ||
|
||
/** | ||
* prendre une donnée dans un champ (colonne d'un fichier tabulé) | ||
* | ||
* @param {String} [path] field path to apply the transformation | ||
* @param {String} [value] value to use during the transformation | ||
* @returns {Object} | ||
*/ | ||
export default function $COLUMN(data, feed) { | ||
return dollar(this, data, feed, transformer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import transformer from './operations/CONCAT_URI'; | ||
import dollar from './dollar'; | ||
|
||
/** | ||
* compoer un identifiant avec plsuieurs champs | ||
* | ||
* @param {String} [path] field path to apply the transformation | ||
* @param {String} [value] value to use during the transformation | ||
* @returns {Object} | ||
*/ | ||
export default function $CONCAT_URI(data, feed) { | ||
return dollar(this, data, feed, transformer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import transformer from './operations/CONCAT'; | ||
import dollar from './dollar'; | ||
|
||
/** | ||
* concaténer deux valeurs | ||
* | ||
* @param {String} [path] field path to apply the transformation | ||
* @param {String} [value] value to use during the transformation | ||
* @returns {Object} | ||
*/ | ||
export default function $CONCAT(data, feed) { | ||
return dollar(this, data, feed, transformer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import transformer from './operations/DEFAULT'; | ||
import dollar from './dollar'; | ||
|
||
/** | ||
* donner une valeur par défaut | ||
* | ||
* @param {String} [path] field path to apply the transformation | ||
* @param {String} [value] value to use during the transformation | ||
* @returns {Object} | ||
*/ | ||
export default function $DEFAULT(data, feed) { | ||
return dollar(this, data, feed, transformer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import transformer from './operations/FORMAT'; | ||
import dollar from './dollar'; | ||
|
||
/** | ||
* appliquer un patron (template) | ||
* | ||
* @param {String} [path] field path to apply the transformation | ||
* @param {String} [value] value to use during the transformation | ||
* @returns {Object} | ||
*/ | ||
export default function $FORMAT(data, feed) { | ||
return dollar(this, data, feed, transformer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import transformer from './operations/GET'; | ||
import dollar from './dollar'; | ||
|
||
/** | ||
* Récupére toutes les valeurs correspondant à un chemin (dot path) | ||
* | ||
* @param {String} [path] field path to apply the transformation | ||
* @param {String} [value] value to use during the transformation | ||
* @returns {Object} | ||
*/ | ||
export default function $GET(data, feed) { | ||
return dollar(this, data, feed, transformer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import transformer from './operations/JOIN'; | ||
import dollar from './dollar'; | ||
|
||
/** | ||
* Rassemble les valeurs d'un tableau en une chaîne de caractères | ||
* | ||
* @param {String} [path] field path to apply the transformation | ||
* @param {String} [value] value to use during the transformation | ||
* @returns {Object} | ||
*/ | ||
export default function $JOIN(data, feed) { | ||
return dollar(this, data, feed, transformer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import transformer from './operations/LOWERCASE'; | ||
import dollar from './dollar'; | ||
|
||
/** | ||
* mettre en bas de casse (minuscules) | ||
* | ||
* @param {String} [path] field path to apply the transformation | ||
* @param {String} [value] value to use during the transformation | ||
* @returns {Object} | ||
*/ | ||
export default function $LOWERCASE(data, feed) { | ||
return dollar(this, data, feed, transformer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import transformer from './operations/MASK'; | ||
import dollar from './dollar'; | ||
|
||
/** | ||
* S'assure que la valeur respecte une expression régulière | ||
* | ||
* @param {String} [path] field path to apply the transformation | ||
* @param {String} [value] value to use during the transformation | ||
* @returns {Object} | ||
*/ | ||
export default function $MASK(data, feed) { | ||
return dollar(this, data, feed, transformer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import transformer from './operations/NUMBER'; | ||
import dollar from './dollar'; | ||
|
||
/** | ||
* transformer une chaîne de caractères en nombre | ||
* | ||
* @param {String} [path] field path to apply the transformation | ||
* @param {String} [value] value to use during the transformation | ||
* @returns {Object} | ||
*/ | ||
export default function $NUMBER(data, feed) { | ||
return dollar(this, data, feed, transformer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import transformer from './operations/PARSE'; | ||
import dollar from './dollar'; | ||
|
||
/** | ||
* Analyser un chaine de caractère comme étant du JSON | ||
* | ||
* @param {String} [path] field path to apply the transformation | ||
* @param {String} [value] value to use during the transformation | ||
* @returns {Object} | ||
*/ | ||
export default function $PARSE(data, feed) { | ||
return dollar(this, data, feed, transformer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import transformer from './operations/PREFIX'; | ||
import dollar from './dollar'; | ||
|
||
/** | ||
* préfixer la valeur avec une chaîne de caractères | ||
* | ||
* @param {String} [path] field path to apply the transformation | ||
* @param {String} [value] value to use during the transformation | ||
* @returns {Object} | ||
*/ | ||
export default function $PREFIX(data, feed) { | ||
return dollar(this, data, feed, transformer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import transformer from './operations/REMOVE'; | ||
import dollar from './dollar'; | ||
|
||
/** | ||
* supprimer un élément ou une sous-chaîne | ||
* | ||
* @param {String} [path] field path to apply the transformation | ||
* @param {String} [value] value to use during the transformation | ||
* @returns {Object} | ||
*/ | ||
export default function $REMOVE(data, feed) { | ||
return dollar(this, data, feed, transformer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import transformer from './operations/REPLACE'; | ||
import dollar from './dollar'; | ||
|
||
/** | ||
* remplacer une chaîne par une autre | ||
* | ||
* @param {String} [path] field path to apply the transformation | ||
* @param {String} [value] value to use during the transformation | ||
* @returns {Object} | ||
*/ | ||
export default function $REPLACE(data, feed) { | ||
return dollar(this, data, feed, transformer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import from from 'from'; | ||
import ezs from '../../core/src'; | ||
import statements from '.'; | ||
|
||
ezs.use(statements); | ||
|
||
describe('$REPLACE', () => { | ||
test('with valid parameter', (done) => { | ||
const script = ` | ||
[$REPLACE] | ||
path = b | ||
searchValue = un | ||
replaceValue = 1 | ||
[exchange] | ||
value = omit('$origin') | ||
`; | ||
const res = []; | ||
from([ | ||
{ a: 1, b: 'un deux', c: true }, | ||
{ a: 2, b: 'un trois', c: true }, | ||
{ a: 3, b: 'un quatre', c: false }, | ||
{ a: 4, b: 'un cinq', c: true }, | ||
]) | ||
.pipe(ezs('delegate', { script })) | ||
.pipe(ezs.catch()) | ||
.on('error', done) | ||
.on('data', (chunk) => { | ||
expect(chunk).toEqual(expect.any(Object)); | ||
res.push(chunk); | ||
}) | ||
.on('end', () => { | ||
expect(res.length).toBe(4) | ||
expect(res[0].b).toEqual('1 deux'); | ||
expect(res[1].b).toEqual('1 trois'); | ||
expect(res[2].b).toEqual('1 quatre'); | ||
expect(res[3].b).toEqual('1 cinq'); | ||
done(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.