Skip to content

Commit

Permalink
feat: 🎸 new package transformers
Browse files Browse the repository at this point in the history
  • Loading branch information
touv committed Feb 25, 2020
1 parent c8bfb85 commit eef6f1f
Show file tree
Hide file tree
Showing 102 changed files with 2,232 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/transformers/.babelrc
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"
]
}
10 changes: 10 additions & 0 deletions packages/transformers/.gitignore
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/
6 changes: 6 additions & 0 deletions packages/transformers/.local.vimrc
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
5 changes: 5 additions & 0 deletions packages/transformers/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
coverage/
bench/
examples/
test/
.nyc_output/
3 changes: 3 additions & 0 deletions packages/transformers/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tabWidth": 4
}
14 changes: 14 additions & 0 deletions packages/transformers/README.md
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

38 changes: 38 additions & 0 deletions packages/transformers/package.json
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": "*"
}
}
13 changes: 13 additions & 0 deletions packages/transformers/src/dollar-array.js
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);
}
13 changes: 13 additions & 0 deletions packages/transformers/src/dollar-autogenerate-uri.js
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);
}
13 changes: 13 additions & 0 deletions packages/transformers/src/dollar-boolean.js
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);
}
13 changes: 13 additions & 0 deletions packages/transformers/src/dollar-capitalize.js
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);
}
13 changes: 13 additions & 0 deletions packages/transformers/src/dollar-column.js
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);
}
13 changes: 13 additions & 0 deletions packages/transformers/src/dollar-concat-uri.js
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);
}
13 changes: 13 additions & 0 deletions packages/transformers/src/dollar-concat.js
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);
}
13 changes: 13 additions & 0 deletions packages/transformers/src/dollar-default.js
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);
}
13 changes: 13 additions & 0 deletions packages/transformers/src/dollar-format.js
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);
}
13 changes: 13 additions & 0 deletions packages/transformers/src/dollar-get.js
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);
}
13 changes: 13 additions & 0 deletions packages/transformers/src/dollar-join.js
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);
}
13 changes: 13 additions & 0 deletions packages/transformers/src/dollar-lowercase.js
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);
}
13 changes: 13 additions & 0 deletions packages/transformers/src/dollar-mask.js
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);
}
13 changes: 13 additions & 0 deletions packages/transformers/src/dollar-number.js
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);
}
13 changes: 13 additions & 0 deletions packages/transformers/src/dollar-parse.js
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);
}
13 changes: 13 additions & 0 deletions packages/transformers/src/dollar-prefix.js
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);
}
13 changes: 13 additions & 0 deletions packages/transformers/src/dollar-remove.js
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);
}
13 changes: 13 additions & 0 deletions packages/transformers/src/dollar-replace.js
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);
}
41 changes: 41 additions & 0 deletions packages/transformers/src/dollar-replace.spec.js
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();
});
});
});
Loading

0 comments on commit eef6f1f

Please sign in to comment.