mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
549ce23ce8
* All projects into monorepo * Update CI * More CI updates * Extracted a bunch of things into packages * Publish - insomnia-plugin-base64@1.0.1 - insomnia-plugin-default-headers@1.0.2 - insomnia-plugin-file@1.0.1 - insomnia-plugin-hash@1.0.1 - insomnia-plugin-now@1.0.1 - insomnia-plugin-request@1.0.1 - insomnia-plugin-response@1.0.1 - insomnia-plugin-uuid@1.0.1 - insomnia-cookies@0.0.2 - insomnia-importers@1.5.2 - insomnia-prettify@0.0.3 - insomnia-url@0.0.2 - insomnia-xpath@0.0.2 * A bunch of small fixes * Improved build script * Fixed * Merge dangling files * Usability refactor * Handle duplicate plugin names
59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
const moment = require('moment');
|
|
|
|
module.exports.templateTags = [{
|
|
name: 'now',
|
|
displayName: 'Timestamp',
|
|
description: 'get the current time',
|
|
args: [
|
|
{
|
|
displayName: 'Timestamp Format',
|
|
type: 'enum',
|
|
options: [
|
|
{displayName: 'ISO-8601', value: 'iso-8601'},
|
|
{displayName: 'Milliseconds', value: 'millis'},
|
|
{displayName: 'Unix', value: 'unix'},
|
|
{displayName: 'Custom Format', value: 'custom'}
|
|
]
|
|
},
|
|
{
|
|
help: 'moment.js format string',
|
|
displayName: 'Custom Format Template',
|
|
type: 'string',
|
|
placeholder: 'MMMM Do YYYY, h:mm:ss a',
|
|
hide: args => args[0].value !== 'custom'
|
|
}
|
|
],
|
|
run (context, dateType = 'iso-8601', formatStr = '') {
|
|
if (typeof dateType === 'string') {
|
|
dateType = dateType.toLowerCase();
|
|
}
|
|
|
|
const now = new Date();
|
|
|
|
switch (dateType) {
|
|
case 'millis':
|
|
case 'ms':
|
|
return now.getTime() + '';
|
|
case 'unix':
|
|
case 'seconds':
|
|
case 's':
|
|
return Math.round(now.getTime() / 1000) + '';
|
|
case 'iso-8601':
|
|
return now.toISOString();
|
|
case 'custom':
|
|
return moment(now).format(formatStr);
|
|
default:
|
|
throw new Error(`Invalid date type "${dateType}"`);
|
|
}
|
|
}
|
|
}, {
|
|
// Old deprecated "timestamp" tag
|
|
deprecated: true,
|
|
name: 'timestamp',
|
|
displayName: 'Timestamp',
|
|
description: 'generate timestamp in milliseconds',
|
|
run (context) {
|
|
return Date.now();
|
|
}
|
|
}];
|