@hapi/hoek
Advanced tools
Comparing version 9.2.1 to 9.3.0
@@ -5,2 +5,3 @@ 'use strict'; | ||
const internals = {}; | ||
@@ -7,0 +8,0 @@ |
@@ -32,4 +32,4 @@ 'use strict'; | ||
const namedEscape = internals.namedHtml[charCode]; | ||
if (typeof namedEscape !== 'undefined') { | ||
const namedEscape = internals.namedHtml.get(charCode); | ||
if (namedEscape) { | ||
return namedEscape; | ||
@@ -49,18 +49,18 @@ } | ||
return (typeof internals.safeCharCodes[charCode] !== 'undefined'); | ||
return internals.safeCharCodes.has(charCode); | ||
}; | ||
internals.namedHtml = { | ||
'38': '&', | ||
'60': '<', | ||
'62': '>', | ||
'34': '"', | ||
'160': ' ', | ||
'162': '¢', | ||
'163': '£', | ||
'164': '¤', | ||
'169': '©', | ||
'174': '®' | ||
}; | ||
internals.namedHtml = new Map([ | ||
[38, '&'], | ||
[60, '<'], | ||
[62, '>'], | ||
[34, '"'], | ||
[160, ' '], | ||
[162, '¢'], | ||
[163, '£'], | ||
[164, '¤'], | ||
[169, '©'], | ||
[174, '®'] | ||
]); | ||
@@ -70,3 +70,3 @@ | ||
const safe = {}; | ||
const safe = new Set(); | ||
@@ -85,3 +85,3 @@ for (let i = 32; i < 123; ++i) { | ||
safe[i] = null; | ||
safe.add(i); | ||
} | ||
@@ -88,0 +88,0 @@ } |
@@ -12,31 +12,18 @@ 'use strict'; | ||
const lessThan = 0x3C; | ||
const greaterThan = 0x3E; | ||
const andSymbol = 0x26; | ||
const lineSeperator = 0x2028; | ||
return input.replace(/[<>&\u2028\u2029]/g, internals.escape); | ||
}; | ||
// replace method | ||
let charCode; | ||
return input.replace(/[<>&\u2028\u2029]/g, (match) => { | ||
charCode = match.charCodeAt(0); | ||
internals.escape = function (char) { | ||
if (charCode === lessThan) { | ||
return '\\u003c'; | ||
} | ||
return internals.replacements.get(char); | ||
}; | ||
if (charCode === greaterThan) { | ||
return '\\u003e'; | ||
} | ||
if (charCode === andSymbol) { | ||
return '\\u0026'; | ||
} | ||
if (charCode === lineSeperator) { | ||
return '\\u2028'; | ||
} | ||
return '\\u2029'; | ||
}); | ||
}; | ||
internals.replacements = new Map([ | ||
['<', '\\u003c'], | ||
['>', '\\u003e'], | ||
['&', '\\u0026'], | ||
['\u2028', '\\u2028'], | ||
['\u2029', '\\u2029'] | ||
]); |
@@ -10,8 +10,8 @@ 'use strict'; | ||
for (let i = 0; i < array.length; ++i) { | ||
if (Array.isArray(array[i])) { | ||
internals.flatten(array[i], result); | ||
for (const entry of array) { | ||
if (Array.isArray(entry)) { | ||
internals.flatten(entry, result); | ||
} | ||
else { | ||
result.push(array[i]); | ||
result.push(entry); | ||
} | ||
@@ -18,0 +18,0 @@ } |
'use strict'; | ||
const internals = {}; | ||
const internals = { | ||
wrapped: Symbol('wrapped') | ||
}; | ||
@@ -8,3 +10,3 @@ | ||
if (method._hoekOnce) { | ||
if (method[internals.wrapped]) { | ||
return method; | ||
@@ -14,3 +16,3 @@ } | ||
let once = false; | ||
const wrapped = function (...args) { | ||
const wrappedFn = function (...args) { | ||
@@ -23,4 +25,4 @@ if (!once) { | ||
wrapped._hoekOnce = true; | ||
return wrapped; | ||
wrappedFn[internals.wrapped] = true; | ||
return wrappedFn; | ||
}; |
@@ -25,3 +25,3 @@ 'use strict'; | ||
Assert(!isChainArray || !options.separator, 'Separator option no valid for array-based chain'); | ||
Assert(!isChainArray || !options.separator, 'Separator option is not valid for array-based chain'); | ||
@@ -28,0 +28,0 @@ const path = isChainArray ? chain : chain.split(options.separator || '.'); |
@@ -9,3 +9,3 @@ 'use strict'; | ||
try { | ||
return JSON.stringify.apply(null, args); | ||
return JSON.stringify(...args); | ||
} | ||
@@ -12,0 +12,0 @@ catch (err) { |
'use strict'; | ||
const internals = {}; | ||
const internals = { | ||
maxTimer: 2 ** 31 - 1 // ~25 days | ||
}; | ||
module.exports = function (timeout, returnValue) { | ||
module.exports = function (timeout, returnValue, options) { | ||
if (typeof timeout === 'bigint') { | ||
timeout = Number(timeout); | ||
} | ||
if (timeout >= Number.MAX_SAFE_INTEGER) { // Thousands of years | ||
timeout = Infinity; | ||
} | ||
if (typeof timeout !== 'number' && timeout !== undefined) { | ||
throw new TypeError('Timeout must be a number'); | ||
throw new TypeError('Timeout must be a number or bigint'); | ||
} | ||
return new Promise((resolve) => setTimeout(resolve, timeout, returnValue)); | ||
return new Promise((resolve) => { | ||
const _setTimeout = options ? options.setTimeout : setTimeout; | ||
const activate = () => { | ||
const time = Math.min(timeout, internals.maxTimer); | ||
timeout -= time; | ||
_setTimeout(() => (timeout > 0 ? activate() : resolve(returnValue)), time); | ||
}; | ||
if (timeout !== Infinity) { | ||
activate(); | ||
} | ||
}); | ||
}; |
{ | ||
"name": "@hapi/hoek", | ||
"description": "General purpose node utilities", | ||
"version": "9.2.1", | ||
"version": "9.3.0", | ||
"repository": "git://github.com/hapijs/hoek", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51451
1479