@extended/timestamp
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -1,11 +0,25 @@ | ||
type Preset = 'LOG' | 'LOG-SHORT' | 'FILE' | 'FILE-SHORT'; | ||
interface Options { | ||
preset?: Preset; | ||
format?: string; | ||
from?: string; | ||
import { type Preset } from './utils/preset'; | ||
interface Options<T extends string> { | ||
format?: T; | ||
UTC?: boolean; | ||
from?: string | Date; | ||
} | ||
declare function timestamp(): string; | ||
declare function timestamp(preset: Preset): string; | ||
declare function timestamp(format: string): string; | ||
declare function timestamp(preset: Preset): string; | ||
declare function timestamp(options: Options): string; | ||
export default timestamp; | ||
declare function timestamp(options: Options<Preset>): string; | ||
declare function timestamp(options: Options<string>): string; | ||
declare function UTCTimestamp(): string; | ||
declare function UTCTimestamp(preset: Preset): string; | ||
declare function UTCTimestamp(format: string): string; | ||
declare function UTCTimestamp(options: Options<Preset>): string; | ||
declare function UTCTimestamp(options: Options<string>): string; | ||
declare function createTimestamp(preset: Preset): typeof timestamp; | ||
declare function createTimestamp(format: string): typeof timestamp; | ||
declare function createTimestamp(options: Options<Preset>): typeof timestamp; | ||
declare function createTimestamp(options: Options<string>): typeof timestamp; | ||
declare const extendedTimestamp: typeof timestamp & { | ||
createTimestamp: typeof createTimestamp; | ||
UTCTimestamp: typeof UTCTimestamp; | ||
}; | ||
export default extendedTimestamp; |
68
index.js
'use strict'; | ||
var index = require('./utils/index.js'); | ||
var DateAdapter = require('./utils/DateAdapter.js'); | ||
var preset = require('./utils/preset.js'); | ||
var format = require('./utils/format.js'); | ||
function timestamp(arg1) { | ||
const date = new Date(); | ||
// // var offset = localDate.getTimezoneOffset(); | ||
// // var utc = new Date(localDate.getTime() - offset * 60000); | ||
// // console.log(offset) | ||
// // console.log(utc) | ||
// console.log(new Date().toString()) | ||
// console.log(new Date().toISOString()) | ||
// console.log(new Date().getHours()) | ||
// console.log(new Date().getUTCHours()) | ||
if (typeof arg1 === 'undefined' || arg1 === 'LOG') { | ||
return (index.getYear(date) + '-' + index.getMonth(date) + '-' + index.getDay(date) + | ||
'T' + | ||
index.getHour(date) + ':' + index.getMinutes(date) + ':' + index.getSeconds(date) + | ||
'.' + index.getMilliseconds(date) + | ||
index.getOffset(date)); | ||
const dateAdapter = new DateAdapter(new Date(), false); | ||
if (typeof arg1 === 'undefined') { | ||
return preset.getPreset(dateAdapter, 'LOG'); | ||
} | ||
if (arg1 === 'LOG-SHORT') { | ||
return (index.getYear(date) + '-' + index.getMonth(date) + '-' + index.getDay(date) + | ||
'T' + | ||
index.getHour(date) + ':' + index.getMinutes(date) + ':' + index.getSeconds(date)); | ||
if (typeof arg1 === 'string') { | ||
return preset.isPreset(arg1) | ||
? preset.getPreset(dateAdapter, arg1) | ||
: format(arg1, dateAdapter); | ||
} | ||
if (arg1 === 'FILE') { | ||
return (index.getYear(date) + '-' + index.getMonth(date) + '-' + index.getDay(date) + | ||
'T' + | ||
index.getHour(date) + '-' + index.getMinutes(date) + '-' + index.getSeconds(date) + | ||
'-' + index.getMilliseconds(date) + | ||
index.getOffset(date, '-')); | ||
else if (typeof arg1 === 'object' && arg1 !== null) { | ||
if (typeof arg1.UTC === 'boolean') { | ||
dateAdapter.UTC = arg1.UTC; | ||
} | ||
if (preset.isPreset(arg1.preset)) { | ||
return preset.getPreset(dateAdapter, arg1); | ||
} | ||
if (typeof arg1.format === 'string') { | ||
return format(arg1.format, dateAdapter); | ||
} | ||
} | ||
if (arg1 === 'FILE-SHORT') { | ||
return (index.getYear(date) + '-' + index.getMonth(date) + '-' + index.getDay(date) + | ||
'T' + | ||
index.getHour(date) + '-' + index.getMinutes(date) + '-' + index.getSeconds(date)); | ||
} | ||
return timestamp(); | ||
return preset.getPreset(dateAdapter, 'LOG'); | ||
} | ||
function UTCTimestamp(arg1) { | ||
return timestamp({ UTC: true }); | ||
} | ||
function createTimestamp(arg1) { | ||
return () => timestamp(); | ||
} | ||
// ----------------------------------------------------------------------------- | ||
const extendedTimestamp = timestamp; | ||
extendedTimestamp.createTimestamp = createTimestamp; | ||
extendedTimestamp.UTCTimestamp = UTCTimestamp; | ||
// ;(() => { | ||
// timestamp('-YYYY-MM-') | ||
// })() | ||
module.exports = timestamp; | ||
module.exports = extendedTimestamp; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@extended/timestamp", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Configurable, versatile, formatted timestamps.", | ||
@@ -65,4 +65,7 @@ "author": "Richard King <richrdkng@gmail.com> (https://richrdkng.com)", | ||
"@types/jest": "^29.5.4", | ||
"@types/luxon": "^3.3.2", | ||
"jest": "^29.6.4", | ||
"jest-extended": "^4.0.1", | ||
"luxon": "^3.4.3", | ||
"moment": "^2.29.4", | ||
"rollup": "^3.28.1", | ||
@@ -69,0 +72,0 @@ "semantic-release": "^19.0.5", |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
22925
15
212
23
1