import * as Messages from "./messages" ; import type Bundle from "./Bundle" ; param date returns export function processDate ( date ) { if ( ! ( date instanceof Date ) ) { throw "Invalid date" ; } const dateParse = dateToW3CString ( date ) ; if ( ! dateParse ) { throw "Invalid date" ; } return dateParse ; } function params returns function dateToW3CString ( date ) { if ( isNaN ( Number ( date ) ) ) { return undefined ; } const paddedMonth = padMeTwo ( date . getMonth ( ) + 1 ) ; const paddedDay = padMeTwo ( date . getDate ( ) ) ; const paddedHour = padMeTwo ( date . getHours ( ) ) ; const paddedMinutes = padMeTwo ( date . getMinutes ( ) ) ; const paddedSeconds = padMeTwo ( date . getSeconds ( ) ) ; see https return `${ date . getFullYear ( ) }-${ paddedMonth }-${ paddedDay }T${ paddedHour }:${ paddedMinutes }:${ paddedSeconds }Z` ; } function padMeTwo ( original ) { return String ( original ) . padStart ( 2 , "0" ) ; } params return export function removeHidden ( from ) { return from . filter ( ( e ) => e . charAt ( 0 ) !== "." ) ; } param object returns export function cloneRecursive < T extends Object > ( object ) { const objectCopy = { } as Record < keyof T , any > ; const objectEntries = Object . entries ( object ) as [ keyof T , T [ keyof T ] ] [ ] ; for ( let i = 0 ; i < objectEntries . length ; i ++ ) { const [ key , value ] = objectEntries [ i ] ; if ( value && typeof value === "object" ) { if ( Array . isArray ( value ) ) { objectCopy [ key ] = value . slice ( ) ; for ( let j = 0 ; j < value . length ; j ++ ) { objectCopy [ key ] [ j ] = cloneRecursive ( value [ j ] ) ; } } else { objectCopy [ key ] = cloneRecursive ( value ) ; } } else { objectCopy [ key ] = value ; } } return objectCopy ; } export function assertUnfrozen ( instance ) { if ( instance . isFrozen ) { throw new Error ( Messages . BUNDLE . CLOSED ) ; } }