diff --git a/index.d.ts b/index.d.ts index 9331ccb..ce32578 100644 --- a/index.d.ts +++ b/index.d.ts @@ -183,6 +183,10 @@ export interface TimestampOptions { * The name of an alias for the timestamp property, that will be added to the `info` object. */ alias?: string; + /** + * The name of the timestamp property, that will take the place of "timestamp" if specified. + */ + propName?: string; } export interface UncolorizeOptions { diff --git a/timestamp.js b/timestamp.js index 706e488..2052fd1 100644 --- a/timestamp.js +++ b/timestamp.js @@ -11,19 +11,19 @@ const format = require('./format'); * - { timestamp: true } // `new Date.toISOString()` * - { timestamp: function:String } // Value returned by `timestamp()` */ -module.exports = format((info, opts = {}) => { +module.exports = format((info, opts = { propName: 'timestamp' }) => { if (opts.format) { - info.timestamp = typeof opts.format === 'function' + info[opts.propName] = typeof opts.format === 'function' ? opts.format() : fecha.format(new Date(), opts.format); } - if (!info.timestamp) { - info.timestamp = new Date().toISOString(); + if (!info[opts.propName]) { + info[opts.propName] = new Date().toISOString(); } if (opts.alias) { - info[opts.alias] = info.timestamp; + info[opts.alias] = info[opts.propName]; } return info;