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)]
|
||||||
13
lib/index.js
13
lib/index.js
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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');
|
const fs = require('fs');
|
||||||
|
|
||||||
class FileSystem {
|
module.exports = registry =>
|
||||||
constructor(registry) {
|
registry.defineDynamicValue('createReadStream', fs.createReadStream);
|
||||||
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"
|
"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"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue