Added date functions.

Added `now` and `date` both allow you to add a timestamp to your
request. Formatting can be controlled globally via the plugin settings
or locally as a final argument when called.
This commit is contained in:
David Diaz 2018-05-14 01:08:03 -06:00
parent 8fdc302ac6
commit 4644fbfd7c
6 changed files with 1067 additions and 1035 deletions

12
beau.yml Normal file
View File

@ -0,0 +1,12 @@
endpoint: https://webhook.site/
plugins:
- std:
date:
format: 'YYYY-MM-DD'
POST /8806bba7-d947-47bf-9445-cccc73e92bb8:
alias: test
payload:
today: $[now(`YYYY`)]
someDay: $[date(2018, 5, 17)]

View File

@ -1,8 +1,13 @@
const date = require('./plugins/date');
const fileSystem = require('./plugins/fileSystem.js');
class STD { class STD {
constructor(registry) { constructor(
const FileSystem = require('./plugins/fileSystem.js'); registry,
new FileSystem(registry); settings = { date: { format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' } }
} ) {
[date, fileSystem].forEach(plugin => plugin(registry, settings));
}
} }
module.exports = STD; module.exports = STD;

13
lib/plugins/date.js Normal file
View File

@ -0,0 +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(
'date',
(year, month, day, fmt = settings.date.format) =>
format(new Date(year, month - 1, day), fmt)
);
};

View File

@ -1,9 +1,4 @@
const fs = require('fs'); const fs = require('fs');
class FileSystem { module.exports = registry =>
constructor(registry) { registry.defineDynamicValue('createReadStream', fs.createReadStream);
registry.defineDynamicValue('createReadStream', fs.createReadStream);
}
}
module.exports = FileSystem;

2051
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,9 @@
"url": "https://github.com/seich/beau-std/issues" "url": "https://github.com/seich/beau-std/issues"
}, },
"homepage": "https://github.com/seich/beau-std#readme", "homepage": "https://github.com/seich/beau-std#readme",
"dependencies": {}, "dependencies": {
"date-fns": "^1.29.0"
},
"devDependencies": { "devDependencies": {
"jest": "^22.4.3" "jest": "^22.4.3"
} }