Skip to content

Commit

Permalink
fix format
Browse files Browse the repository at this point in the history
Signed-off-by: francesco <[email protected]>
  • Loading branch information
cesco69 authored Apr 11, 2024
1 parent 16c54b9 commit ab473e9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const STR_ESCAPE = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]/

module.exports = class Serializer {
constructor(options) {
constructor (options) {
switch (options && options.rounding) {
case 'floor':
this.parseInteger = Math.floor
Expand All @@ -23,7 +23,7 @@ module.exports = class Serializer {
this._options = options
}

asInteger(i) {
asInteger (i) {
if (Number.isInteger(i)) {
return '' + i
} else if (typeof i === 'bigint') {
Expand All @@ -39,7 +39,7 @@ module.exports = class Serializer {
return '' + integer
}

asNumber(i) {
asNumber (i) {
// fast cast to number
const num = +i
// check if number is NaN
Expand All @@ -53,7 +53,7 @@ module.exports = class Serializer {
}
}

asBoolean(bool) {
asBoolean (bool) {
return bool && 'true' || 'false' // eslint-disable-line
}

Expand All @@ -68,7 +68,7 @@ module.exports = class Serializer {
throw new Error(`The value "${date}" cannot be converted to a date-time.`)
}

asDate(date) {
asDate (date) {
if (date === null) return '""'
if (date instanceof Date) {
return '"' + new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toISOString().slice(0, 10) + '"'
Expand All @@ -79,7 +79,7 @@ module.exports = class Serializer {
throw new Error(`The value "${date}" cannot be converted to a date.`)
}

asTime(date) {
asTime (date) {
if (date === null) return '""'
if (date instanceof Date) {
return '"' + new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toISOString().slice(11, 19) + '"'
Expand All @@ -90,7 +90,7 @@ module.exports = class Serializer {
throw new Error(`The value "${date}" cannot be converted to a time.`)
}

asString(str) {
asString (str) {
const len = str.length
if (len < 42) {
// magically escape strings for json
Expand Down Expand Up @@ -126,15 +126,15 @@ module.exports = class Serializer {
}
}

asUnsafeString(str) {
asUnsafeString (str) {
return '"' + str + '"'
}

getState() {
getState () {
return this._options
}

static restoreFromState(state) {
static restoreFromState (state) {
return new Serializer(state)
}
}

0 comments on commit ab473e9

Please sign in to comment.