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:
parent
8fdc302ac6
commit
4644fbfd7c
|
|
@ -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)]
|
||||
11
lib/index.js
11
lib/index.js
|
|
@ -1,7 +1,12 @@
|
|||
const date = require('./plugins/date');
|
||||
const fileSystem = require('./plugins/fileSystem.js');
|
||||
|
||||
class STD {
|
||||
constructor(registry) {
|
||||
const FileSystem = require('./plugins/fileSystem.js');
|
||||
new FileSystem(registry);
|
||||
constructor(
|
||||
registry,
|
||||
settings = { date: { format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' } }
|
||||
) {
|
||||
[date, fileSystem].forEach(plugin => plugin(registry, settings));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
);
|
||||
};
|
||||
|
|
@ -1,9 +1,4 @@
|
|||
const fs = require('fs');
|
||||
|
||||
class FileSystem {
|
||||
constructor(registry) {
|
||||
module.exports = registry =>
|
||||
registry.defineDynamicValue('createReadStream', fs.createReadStream);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FileSystem;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -19,7 +19,9 @@
|
|||
"url": "https://github.com/seich/beau-std/issues"
|
||||
},
|
||||
"homepage": "https://github.com/seich/beau-std#readme",
|
||||
"dependencies": {},
|
||||
"dependencies": {
|
||||
"date-fns": "^1.29.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^22.4.3"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue