Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 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) {

Check failure on line 7 in lib/serializer.js

View workflow job for this annotation

GitHub Actions / test / quality-check / Lint Code

Missing space before function parentheses
switch (options && options.rounding) {
case 'floor':
this.parseInteger = Math.floor
Expand All @@ -23,7 +23,7 @@
this._options = options
}

asInteger (i) {
asInteger(i) {

Check failure on line 26 in lib/serializer.js

View workflow job for this annotation

GitHub Actions / test / quality-check / Lint Code

Missing space before function parentheses
if (Number.isInteger(i)) {
return '' + i
} else if (typeof i === 'bigint') {
Expand All @@ -39,7 +39,7 @@
return '' + integer
}

asNumber (i) {
asNumber(i) {

Check failure on line 42 in lib/serializer.js

View workflow job for this annotation

GitHub Actions / test / quality-check / Lint Code

Missing space before function parentheses
// fast cast to number
const num = Number(i)
// check if number is NaN
Expand All @@ -53,11 +53,11 @@
}
}

asBoolean (bool) {
asBoolean(bool) {

Check failure on line 56 in lib/serializer.js

View workflow job for this annotation

GitHub Actions / test / quality-check / Lint Code

Missing space before function parentheses
return bool && 'true' || 'false' // eslint-disable-line
}

asDateTime (date) {
asDateTime(date) {

Check failure on line 60 in lib/serializer.js

View workflow job for this annotation

GitHub Actions / test / quality-check / Lint Code

Missing space before function parentheses
if (date === null) return '""'
if (date instanceof Date) {
return '"' + date.toISOString() + '"'
Expand All @@ -68,7 +68,7 @@
throw new Error(`The value "${date}" cannot be converted to a date-time.`)
}

asDate (date) {
asDate(date) {

Check failure on line 71 in lib/serializer.js

View workflow job for this annotation

GitHub Actions / test / quality-check / Lint Code

Missing space before function parentheses
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 @@
throw new Error(`The value "${date}" cannot be converted to a date.`)
}

asTime (date) {
asTime(date) {

Check failure on line 82 in lib/serializer.js

View workflow job for this annotation

GitHub Actions / test / quality-check / Lint Code

Missing space before function parentheses
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 @@
throw new Error(`The value "${date}" cannot be converted to a time.`)
}

asString (str) {
asString(str) {

Check failure on line 93 in lib/serializer.js

View workflow job for this annotation

GitHub Actions / test / quality-check / Lint Code

Missing space before function parentheses
const len = str.length
if (len === 0) {
return '""'
Expand Down Expand Up @@ -119,23 +119,23 @@
}
}
return (last === -1 && ('"' + str + '"')) || ('"' + result + str.slice(last) + '"')
} else if (len < 5000 && STR_ESCAPE.test(str) === false) {
} else if (len < 2000 && STR_ESCAPE.test(str) === false) {
// Only use the regular expression for shorter input. The overhead is otherwise too much.
return '"' + str + '"'
} else {
return JSON.stringify(str)
}
}

asUnsafeString (str) {
asUnsafeString(str) {

Check failure on line 130 in lib/serializer.js

View workflow job for this annotation

GitHub Actions / test / quality-check / Lint Code

Missing space before function parentheses
return '"' + str + '"'
}

getState () {
getState() {

Check failure on line 134 in lib/serializer.js

View workflow job for this annotation

GitHub Actions / test / quality-check / Lint Code

Missing space before function parentheses
return this._options
}

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