From ed96cce40ef83c08006841bac4a224a77d33d4f9 Mon Sep 17 00:00:00 2001 From: David Pfeffer Date: Thu, 18 Apr 2024 07:52:53 -0400 Subject: [PATCH 1/3] Add option to wholesale replace the timestamp property with another --- timestamp.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/timestamp.js b/timestamp.js index 706e488..f87dafe 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[propName]) { + info[opts.propName] = new Date().toISOString(); } if (opts.alias) { - info[opts.alias] = info.timestamp; + info[opts.alias] = info[opts.propName]; } return info; From 69aeb4b582d18a74040db1587d47d2eace1a8edd Mon Sep 17 00:00:00 2001 From: David Pfeffer Date: Thu, 18 Apr 2024 07:55:11 -0400 Subject: [PATCH 2/3] Added type information for timestamp propName --- index.d.ts | 4 ++++ 1 file changed, 4 insertions(+) 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 { From 095b8baab4ad5bffd8b12f2b36eabace8fa67c22 Mon Sep 17 00:00:00 2001 From: David Pfeffer Date: Fri, 5 Jul 2024 10:01:32 -0400 Subject: [PATCH 3/3] lint fixes --- timestamp.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/timestamp.js b/timestamp.js index f87dafe..2052fd1 100644 --- a/timestamp.js +++ b/timestamp.js @@ -11,14 +11,14 @@ const format = require('./format'); * - { timestamp: true } // `new Date.toISOString()` * - { timestamp: function:String } // Value returned by `timestamp()` */ -module.exports = format((info, opts = {propName: 'timestamp'}) => { +module.exports = format((info, opts = { propName: 'timestamp' }) => { if (opts.format) { info[opts.propName] = typeof opts.format === 'function' ? opts.format() : fecha.format(new Date(), opts.format); } - if (!info[propName]) { + if (!info[opts.propName]) { info[opts.propName] = new Date().toISOString(); }