From 74d29859f3724f24b72c333c379ed5299be2456d Mon Sep 17 00:00:00 2001 From: David Diaz Date: Tue, 19 Jun 2018 10:00:57 -0600 Subject: [PATCH] Updated the example. Added uuid. --- beau.yml | 17 ++++++++++++++--- lib/index.js | 15 ++++++++------- lib/plugins/date.js | 16 ++++++++-------- lib/plugins/uuid.js | 3 +++ package-lock.json | 5 +++++ package.json | 3 ++- 6 files changed, 40 insertions(+), 19 deletions(-) create mode 100644 lib/plugins/uuid.js diff --git a/beau.yml b/beau.yml index 6de1818..857f9af 100644 --- a/beau.yml +++ b/beau.yml @@ -1,12 +1,23 @@ -endpoint: https://webhook.site/ +endpoint: https://httpbin.org/ plugins: - std: date: format: 'YYYY-MM-DD' -POST /8806bba7-d947-47bf-9445-cccc73e92bb8: - alias: test +POST /anything: + alias: date payload: today: $[now(`YYYY`)] someDay: $[date(2018, 5, 17)] + +POST /anything?1: + alias: uuid + payload: + uuid: $[uuid()] + +POST /anything?2: + alias: upload + formdata: + file: $[createReadStream('./LICENSE')] + diff --git a/lib/index.js b/lib/index.js index 6ecc144..4dbef83 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,13 +1,14 @@ const date = require('./plugins/date'); -const fileSystem = require('./plugins/fileSystem.js'); +const fileSystem = require('./plugins/fileSystem'); +const uuid = require('./plugins/uuid'); class STD { - constructor( - registry, - settings = { date: { format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' } } - ) { - [date, fileSystem].forEach(plugin => plugin(registry, settings)); - } + constructor(registry, settings) { + const defaults = { date: { format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' } }; + settings = Object.assign({}, defaults, settings); + + [date, fileSystem, uuid].forEach(plugin => plugin(registry, settings)); + } } module.exports = STD; diff --git a/lib/plugins/date.js b/lib/plugins/date.js index 5eba546..8484fa5 100644 --- a/lib/plugins/date.js +++ b/lib/plugins/date.js @@ -1,13 +1,13 @@ const format = require('date-fns/format'); module.exports = (registry, settings) => { - registry.defineDynamicValue('now', (fmt = settings.date.format) => - format(Date.now(), fmt) - ); + registry.defineDynamicValue('now', (fmt = settings.date.format) => + format(Date.now(), fmt) + ); - registry.defineDynamicValue( - 'date', - (year, month, day, fmt = settings.date.format) => - format(new Date(year, month - 1, day), fmt) - ); + registry.defineDynamicValue( + 'date', + (year, month, day, fmt = settings.date.format) => + format(new Date(year, month - 1, day), fmt) + ); }; diff --git a/lib/plugins/uuid.js b/lib/plugins/uuid.js new file mode 100644 index 0000000..0803ab4 --- /dev/null +++ b/lib/plugins/uuid.js @@ -0,0 +1,3 @@ +const uuid = require('uuid/v4'); + +module.exports = registry => registry.defineDynamicValue('uuid', uuid); diff --git a/package-lock.json b/package-lock.json index 898f545..5bbc542 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,11 @@ "version": "1.29.0", "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-1.29.0.tgz", "integrity": "sha512-lbTXWZ6M20cWH8N9S6afb0SBm6tMk+uUg6z3MqHPKE9atmsY3kJkTm8vKe93izJ2B2+q5MV990sM2CHgtAZaOw==" + }, + "uuid": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.2.1.tgz", + "integrity": "sha512-jZnMwlb9Iku/O3smGWvZhauCf6cvvpKi4BKRiliS3cxnI+Gz9j5MEpTz2UFuXiKPJocb7gnsLHwiS05ige5BEA==" } } } diff --git a/package.json b/package.json index 22b1817..07ffd17 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ }, "homepage": "https://github.com/seich/beau-std#readme", "dependencies": { - "date-fns": "^1.29.0" + "date-fns": "^1.29.0", + "uuid": "^3.2.1" }, "devDependencies": {} }