update
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
var noop = function () { };
|
||||
var path = require('path');
|
||||
const semver = require('semver');
|
||||
var version = process.versions.node.split('.') || [null, null, null];
|
||||
|
||||
var utils = (module.exports = {
|
||||
semver: semver,
|
||||
satisfies: test => semver.satisfies(process.versions.node, test),
|
||||
version: {
|
||||
major: parseInt(version[0] || 0, 10),
|
||||
minor: parseInt(version[1] || 0, 10),
|
||||
patch: parseInt(version[2] || 0, 10),
|
||||
},
|
||||
clone: require('./clone'),
|
||||
merge: require('./merge'),
|
||||
bus: require('./bus'),
|
||||
isWindows: process.platform === 'win32',
|
||||
isMac: process.platform === 'darwin',
|
||||
isLinux: process.platform === 'linux',
|
||||
isIBMi: require('os').type() === 'OS400',
|
||||
isRequired: (function () {
|
||||
var p = module.parent;
|
||||
while (p) {
|
||||
// in electron.js engine it happens
|
||||
if (!p.filename) {
|
||||
return true;
|
||||
}
|
||||
if (p.filename.indexOf('bin' + path.sep + 'nodemon.js') !== -1) {
|
||||
return false;
|
||||
}
|
||||
p = p.parent;
|
||||
}
|
||||
|
||||
return true;
|
||||
})(),
|
||||
home: process.env.HOME || process.env.HOMEPATH,
|
||||
quiet: function () {
|
||||
// nukes the logging
|
||||
if (!this.debug) {
|
||||
for (var method in utils.log) {
|
||||
if (typeof utils.log[method] === 'function') {
|
||||
utils.log[method] = noop;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
reset: function () {
|
||||
if (!this.debug) {
|
||||
for (var method in utils.log) {
|
||||
if (typeof utils.log[method] === 'function') {
|
||||
delete utils.log[method];
|
||||
}
|
||||
}
|
||||
}
|
||||
this.debug = false;
|
||||
},
|
||||
regexpToText: function (t) {
|
||||
return t
|
||||
.replace(/\.\*\\./g, '*.')
|
||||
.replace(/\\{2}/g, '^^')
|
||||
.replace(/\\/g, '')
|
||||
.replace(/\^\^/g, '\\');
|
||||
},
|
||||
stringify: function (exec, args) {
|
||||
// serializes an executable string and array of arguments into a string
|
||||
args = args || [];
|
||||
|
||||
return [exec]
|
||||
.concat(
|
||||
args.map(function (arg) {
|
||||
// if an argument contains a space, we want to show it with quotes
|
||||
// around it to indicate that it is a single argument
|
||||
if (arg.length > 0 && arg.indexOf(' ') === -1) {
|
||||
return arg;
|
||||
}
|
||||
// this should correctly escape nested quotes
|
||||
return JSON.stringify(arg);
|
||||
})
|
||||
)
|
||||
.join(' ')
|
||||
.trim();
|
||||
},
|
||||
});
|
||||
|
||||
utils.log = require('./log')(utils.isRequired);
|
||||
|
||||
Object.defineProperty(utils, 'debug', {
|
||||
set: function (value) {
|
||||
this.log.debug = value;
|
||||
},
|
||||
get: function () {
|
||||
return this.log.debug;
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(utils, 'colours', {
|
||||
set: function (value) {
|
||||
this.log.useColours = value;
|
||||
},
|
||||
get: function () {
|
||||
return this.log.useColours;
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2010 Sencha Inc.
|
||||
Copyright (c) 2011 LearnBoost
|
||||
Copyright (c) 2011 TJ Holowaychuk
|
||||
Copyright (c) 2014-2016 Douglas Christopher Wilson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
const compare = require('./compare')
|
||||
const eq = (a, b, loose) => compare(a, b, loose) === 0
|
||||
module.exports = eq
|
||||
@@ -0,0 +1,192 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
var v = require('es-value-fixtures');
|
||||
var forEach = require('for-each');
|
||||
var inspect = require('object-inspect');
|
||||
|
||||
var abs = require('../abs');
|
||||
var floor = require('../floor');
|
||||
var isFinite = require('../isFinite');
|
||||
var isInteger = require('../isInteger');
|
||||
var isNaN = require('../isNaN');
|
||||
var isNegativeZero = require('../isNegativeZero');
|
||||
var max = require('../max');
|
||||
var min = require('../min');
|
||||
var mod = require('../mod');
|
||||
var pow = require('../pow');
|
||||
var round = require('../round');
|
||||
var sign = require('../sign');
|
||||
|
||||
var maxArrayLength = require('../constants/maxArrayLength');
|
||||
var maxSafeInteger = require('../constants/maxSafeInteger');
|
||||
var maxValue = require('../constants/maxValue');
|
||||
|
||||
test('abs', function (t) {
|
||||
t.equal(abs(-1), 1, 'abs(-1) === 1');
|
||||
t.equal(abs(+1), 1, 'abs(+1) === 1');
|
||||
t.equal(abs(+0), +0, 'abs(+0) === +0');
|
||||
t.equal(abs(-0), +0, 'abs(-0) === +0');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('floor', function (t) {
|
||||
t.equal(floor(-1.1), -2, 'floor(-1.1) === -2');
|
||||
t.equal(floor(+1.1), 1, 'floor(+1.1) === 1');
|
||||
t.equal(floor(+0), +0, 'floor(+0) === +0');
|
||||
t.equal(floor(-0), -0, 'floor(-0) === -0');
|
||||
t.equal(floor(-Infinity), -Infinity, 'floor(-Infinity) === -Infinity');
|
||||
t.equal(floor(Number(Infinity)), Number(Infinity), 'floor(+Infinity) === +Infinity');
|
||||
t.equal(floor(NaN), NaN, 'floor(NaN) === NaN');
|
||||
t.equal(floor(0), +0, 'floor(0) === +0');
|
||||
t.equal(floor(-0), -0, 'floor(-0) === -0');
|
||||
t.equal(floor(1), 1, 'floor(1) === 1');
|
||||
t.equal(floor(-1), -1, 'floor(-1) === -1');
|
||||
t.equal(floor(1.1), 1, 'floor(1.1) === 1');
|
||||
t.equal(floor(-1.1), -2, 'floor(-1.1) === -2');
|
||||
t.equal(floor(maxValue), maxValue, 'floor(maxValue) === maxValue');
|
||||
t.equal(floor(maxSafeInteger), maxSafeInteger, 'floor(maxSafeInteger) === maxSafeInteger');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('isFinite', function (t) {
|
||||
t.equal(isFinite(0), true, 'isFinite(+0) === true');
|
||||
t.equal(isFinite(-0), true, 'isFinite(-0) === true');
|
||||
t.equal(isFinite(1), true, 'isFinite(1) === true');
|
||||
t.equal(isFinite(Infinity), false, 'isFinite(Infinity) === false');
|
||||
t.equal(isFinite(-Infinity), false, 'isFinite(-Infinity) === false');
|
||||
t.equal(isFinite(NaN), false, 'isFinite(NaN) === false');
|
||||
|
||||
forEach(v.nonNumbers, function (nonNumber) {
|
||||
t.equal(isFinite(nonNumber), false, 'isFinite(' + inspect(nonNumber) + ') === false');
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('isInteger', function (t) {
|
||||
forEach([].concat(
|
||||
// @ts-expect-error TS sucks with concat
|
||||
v.nonNumbers,
|
||||
v.nonIntegerNumbers
|
||||
), function (nonInteger) {
|
||||
t.equal(isInteger(nonInteger), false, 'isInteger(' + inspect(nonInteger) + ') === false');
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('isNaN', function (t) {
|
||||
forEach([].concat(
|
||||
// @ts-expect-error TS sucks with concat
|
||||
v.nonNumbers,
|
||||
v.infinities,
|
||||
v.zeroes,
|
||||
v.integerNumbers
|
||||
), function (nonNaN) {
|
||||
t.equal(isNaN(nonNaN), false, 'isNaN(' + inspect(nonNaN) + ') === false');
|
||||
});
|
||||
|
||||
t.equal(isNaN(NaN), true, 'isNaN(NaN) === true');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('isNegativeZero', function (t) {
|
||||
t.equal(isNegativeZero(-0), true, 'isNegativeZero(-0) === true');
|
||||
t.equal(isNegativeZero(+0), false, 'isNegativeZero(+0) === false');
|
||||
t.equal(isNegativeZero(1), false, 'isNegativeZero(1) === false');
|
||||
t.equal(isNegativeZero(-1), false, 'isNegativeZero(-1) === false');
|
||||
t.equal(isNegativeZero(NaN), false, 'isNegativeZero(NaN) === false');
|
||||
t.equal(isNegativeZero(Infinity), false, 'isNegativeZero(Infinity) === false');
|
||||
t.equal(isNegativeZero(-Infinity), false, 'isNegativeZero(-Infinity) === false');
|
||||
|
||||
forEach(v.nonNumbers, function (nonNumber) {
|
||||
t.equal(isNegativeZero(nonNumber), false, 'isNegativeZero(' + inspect(nonNumber) + ') === false');
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('max', function (t) {
|
||||
t.equal(max(1, 2), 2, 'max(1, 2) === 2');
|
||||
t.equal(max(1, 2, 3), 3, 'max(1, 2, 3) === 3');
|
||||
t.equal(max(1, 2, 3, 4), 4, 'max(1, 2, 3, 4) === 4');
|
||||
t.equal(max(1, 2, 3, 4, 5), 5, 'max(1, 2, 3, 4, 5) === 5');
|
||||
t.equal(max(1, 2, 3, 4, 5, 6), 6, 'max(1, 2, 3, 4, 5, 6) === 6');
|
||||
t.equal(max(1, 2, 3, 4, 5, 6, 7), 7, 'max(1, 2, 3, 4, 5, 6, 7) === 7');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('min', function (t) {
|
||||
t.equal(min(1, 2), 1, 'min(1, 2) === 1');
|
||||
t.equal(min(1, 2, 3), 1, 'min(1, 2, 3) === 1');
|
||||
t.equal(min(1, 2, 3, 4), 1, 'min(1, 2, 3, 4) === 1');
|
||||
t.equal(min(1, 2, 3, 4, 5), 1, 'min(1, 2, 3, 4, 5) === 1');
|
||||
t.equal(min(1, 2, 3, 4, 5, 6), 1, 'min(1, 2, 3, 4, 5, 6) === 1');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('mod', function (t) {
|
||||
t.equal(mod(1, 2), 1, 'mod(1, 2) === 1');
|
||||
t.equal(mod(2, 2), 0, 'mod(2, 2) === 0');
|
||||
t.equal(mod(3, 2), 1, 'mod(3, 2) === 1');
|
||||
t.equal(mod(4, 2), 0, 'mod(4, 2) === 0');
|
||||
t.equal(mod(5, 2), 1, 'mod(5, 2) === 1');
|
||||
t.equal(mod(6, 2), 0, 'mod(6, 2) === 0');
|
||||
t.equal(mod(7, 2), 1, 'mod(7, 2) === 1');
|
||||
t.equal(mod(8, 2), 0, 'mod(8, 2) === 0');
|
||||
t.equal(mod(9, 2), 1, 'mod(9, 2) === 1');
|
||||
t.equal(mod(10, 2), 0, 'mod(10, 2) === 0');
|
||||
t.equal(mod(11, 2), 1, 'mod(11, 2) === 1');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('pow', function (t) {
|
||||
t.equal(pow(2, 2), 4, 'pow(2, 2) === 4');
|
||||
t.equal(pow(2, 3), 8, 'pow(2, 3) === 8');
|
||||
t.equal(pow(2, 4), 16, 'pow(2, 4) === 16');
|
||||
t.equal(pow(2, 5), 32, 'pow(2, 5) === 32');
|
||||
t.equal(pow(2, 6), 64, 'pow(2, 6) === 64');
|
||||
t.equal(pow(2, 7), 128, 'pow(2, 7) === 128');
|
||||
t.equal(pow(2, 8), 256, 'pow(2, 8) === 256');
|
||||
t.equal(pow(2, 9), 512, 'pow(2, 9) === 512');
|
||||
t.equal(pow(2, 10), 1024, 'pow(2, 10) === 1024');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('round', function (t) {
|
||||
t.equal(round(1.1), 1, 'round(1.1) === 1');
|
||||
t.equal(round(1.5), 2, 'round(1.5) === 2');
|
||||
t.equal(round(1.9), 2, 'round(1.9) === 2');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('sign', function (t) {
|
||||
t.equal(sign(-1), -1, 'sign(-1) === -1');
|
||||
t.equal(sign(+1), +1, 'sign(+1) === +1');
|
||||
t.equal(sign(+0), +0, 'sign(+0) === +0');
|
||||
t.equal(sign(-0), -0, 'sign(-0) === -0');
|
||||
t.equal(sign(NaN), NaN, 'sign(NaN) === NaN');
|
||||
t.equal(sign(Infinity), +1, 'sign(Infinity) === +1');
|
||||
t.equal(sign(-Infinity), -1, 'sign(-Infinity) === -1');
|
||||
t.equal(sign(maxValue), +1, 'sign(maxValue) === +1');
|
||||
t.equal(sign(maxSafeInteger), +1, 'sign(maxSafeInteger) === +1');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('constants', function (t) {
|
||||
t.equal(typeof maxArrayLength, 'number', 'typeof maxArrayLength === "number"');
|
||||
t.equal(typeof maxSafeInteger, 'number', 'typeof maxSafeInteger === "number"');
|
||||
t.equal(typeof maxValue, 'number', 'typeof maxValue === "number"');
|
||||
|
||||
t.end();
|
||||
});
|
||||
@@ -0,0 +1,336 @@
|
||||
/*!
|
||||
* raw-body
|
||||
* Copyright(c) 2013-2014 Jonathan Ong
|
||||
* Copyright(c) 2014-2022 Douglas Christopher Wilson
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
* @private
|
||||
*/
|
||||
|
||||
var asyncHooks = tryRequireAsyncHooks()
|
||||
var bytes = require('bytes')
|
||||
var createError = require('http-errors')
|
||||
var iconv = require('iconv-lite')
|
||||
var unpipe = require('unpipe')
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
* @public
|
||||
*/
|
||||
|
||||
module.exports = getRawBody
|
||||
|
||||
/**
|
||||
* Module variables.
|
||||
* @private
|
||||
*/
|
||||
|
||||
var ICONV_ENCODING_MESSAGE_REGEXP = /^Encoding not recognized: /
|
||||
|
||||
/**
|
||||
* Get the decoder for a given encoding.
|
||||
*
|
||||
* @param {string} encoding
|
||||
* @private
|
||||
*/
|
||||
|
||||
function getDecoder (encoding) {
|
||||
if (!encoding) return null
|
||||
|
||||
try {
|
||||
return iconv.getDecoder(encoding)
|
||||
} catch (e) {
|
||||
// error getting decoder
|
||||
if (!ICONV_ENCODING_MESSAGE_REGEXP.test(e.message)) throw e
|
||||
|
||||
// the encoding was not found
|
||||
throw createError(415, 'specified encoding unsupported', {
|
||||
encoding: encoding,
|
||||
type: 'encoding.unsupported'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw body of a stream (typically HTTP).
|
||||
*
|
||||
* @param {object} stream
|
||||
* @param {object|string|function} [options]
|
||||
* @param {function} [callback]
|
||||
* @public
|
||||
*/
|
||||
|
||||
function getRawBody (stream, options, callback) {
|
||||
var done = callback
|
||||
var opts = options || {}
|
||||
|
||||
// light validation
|
||||
if (stream === undefined) {
|
||||
throw new TypeError('argument stream is required')
|
||||
} else if (typeof stream !== 'object' || stream === null || typeof stream.on !== 'function') {
|
||||
throw new TypeError('argument stream must be a stream')
|
||||
}
|
||||
|
||||
if (options === true || typeof options === 'string') {
|
||||
// short cut for encoding
|
||||
opts = {
|
||||
encoding: options
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof options === 'function') {
|
||||
done = options
|
||||
opts = {}
|
||||
}
|
||||
|
||||
// validate callback is a function, if provided
|
||||
if (done !== undefined && typeof done !== 'function') {
|
||||
throw new TypeError('argument callback must be a function')
|
||||
}
|
||||
|
||||
// require the callback without promises
|
||||
if (!done && !global.Promise) {
|
||||
throw new TypeError('argument callback is required')
|
||||
}
|
||||
|
||||
// get encoding
|
||||
var encoding = opts.encoding !== true
|
||||
? opts.encoding
|
||||
: 'utf-8'
|
||||
|
||||
// convert the limit to an integer
|
||||
var limit = bytes.parse(opts.limit)
|
||||
|
||||
// convert the expected length to an integer
|
||||
var length = opts.length != null && !isNaN(opts.length)
|
||||
? parseInt(opts.length, 10)
|
||||
: null
|
||||
|
||||
if (done) {
|
||||
// classic callback style
|
||||
return readStream(stream, encoding, length, limit, wrap(done))
|
||||
}
|
||||
|
||||
return new Promise(function executor (resolve, reject) {
|
||||
readStream(stream, encoding, length, limit, function onRead (err, buf) {
|
||||
if (err) return reject(err)
|
||||
resolve(buf)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Halt a stream.
|
||||
*
|
||||
* @param {Object} stream
|
||||
* @private
|
||||
*/
|
||||
|
||||
function halt (stream) {
|
||||
// unpipe everything from the stream
|
||||
unpipe(stream)
|
||||
|
||||
// pause stream
|
||||
if (typeof stream.pause === 'function') {
|
||||
stream.pause()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the data from the stream.
|
||||
*
|
||||
* @param {object} stream
|
||||
* @param {string} encoding
|
||||
* @param {number} length
|
||||
* @param {number} limit
|
||||
* @param {function} callback
|
||||
* @public
|
||||
*/
|
||||
|
||||
function readStream (stream, encoding, length, limit, callback) {
|
||||
var complete = false
|
||||
var sync = true
|
||||
|
||||
// check the length and limit options.
|
||||
// note: we intentionally leave the stream paused,
|
||||
// so users should handle the stream themselves.
|
||||
if (limit !== null && length !== null && length > limit) {
|
||||
return done(createError(413, 'request entity too large', {
|
||||
expected: length,
|
||||
length: length,
|
||||
limit: limit,
|
||||
type: 'entity.too.large'
|
||||
}))
|
||||
}
|
||||
|
||||
// streams1: assert request encoding is buffer.
|
||||
// streams2+: assert the stream encoding is buffer.
|
||||
// stream._decoder: streams1
|
||||
// state.encoding: streams2
|
||||
// state.decoder: streams2, specifically < 0.10.6
|
||||
var state = stream._readableState
|
||||
if (stream._decoder || (state && (state.encoding || state.decoder))) {
|
||||
// developer error
|
||||
return done(createError(500, 'stream encoding should not be set', {
|
||||
type: 'stream.encoding.set'
|
||||
}))
|
||||
}
|
||||
|
||||
if (typeof stream.readable !== 'undefined' && !stream.readable) {
|
||||
return done(createError(500, 'stream is not readable', {
|
||||
type: 'stream.not.readable'
|
||||
}))
|
||||
}
|
||||
|
||||
var received = 0
|
||||
var decoder
|
||||
|
||||
try {
|
||||
decoder = getDecoder(encoding)
|
||||
} catch (err) {
|
||||
return done(err)
|
||||
}
|
||||
|
||||
var buffer = decoder
|
||||
? ''
|
||||
: []
|
||||
|
||||
// attach listeners
|
||||
stream.on('aborted', onAborted)
|
||||
stream.on('close', cleanup)
|
||||
stream.on('data', onData)
|
||||
stream.on('end', onEnd)
|
||||
stream.on('error', onEnd)
|
||||
|
||||
// mark sync section complete
|
||||
sync = false
|
||||
|
||||
function done () {
|
||||
var args = new Array(arguments.length)
|
||||
|
||||
// copy arguments
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
args[i] = arguments[i]
|
||||
}
|
||||
|
||||
// mark complete
|
||||
complete = true
|
||||
|
||||
if (sync) {
|
||||
process.nextTick(invokeCallback)
|
||||
} else {
|
||||
invokeCallback()
|
||||
}
|
||||
|
||||
function invokeCallback () {
|
||||
cleanup()
|
||||
|
||||
if (args[0]) {
|
||||
// halt the stream on error
|
||||
halt(stream)
|
||||
}
|
||||
|
||||
callback.apply(null, args)
|
||||
}
|
||||
}
|
||||
|
||||
function onAborted () {
|
||||
if (complete) return
|
||||
|
||||
done(createError(400, 'request aborted', {
|
||||
code: 'ECONNABORTED',
|
||||
expected: length,
|
||||
length: length,
|
||||
received: received,
|
||||
type: 'request.aborted'
|
||||
}))
|
||||
}
|
||||
|
||||
function onData (chunk) {
|
||||
if (complete) return
|
||||
|
||||
received += chunk.length
|
||||
|
||||
if (limit !== null && received > limit) {
|
||||
done(createError(413, 'request entity too large', {
|
||||
limit: limit,
|
||||
received: received,
|
||||
type: 'entity.too.large'
|
||||
}))
|
||||
} else if (decoder) {
|
||||
buffer += decoder.write(chunk)
|
||||
} else {
|
||||
buffer.push(chunk)
|
||||
}
|
||||
}
|
||||
|
||||
function onEnd (err) {
|
||||
if (complete) return
|
||||
if (err) return done(err)
|
||||
|
||||
if (length !== null && received !== length) {
|
||||
done(createError(400, 'request size did not match content length', {
|
||||
expected: length,
|
||||
length: length,
|
||||
received: received,
|
||||
type: 'request.size.invalid'
|
||||
}))
|
||||
} else {
|
||||
var string = decoder
|
||||
? buffer + (decoder.end() || '')
|
||||
: Buffer.concat(buffer)
|
||||
done(null, string)
|
||||
}
|
||||
}
|
||||
|
||||
function cleanup () {
|
||||
buffer = null
|
||||
|
||||
stream.removeListener('aborted', onAborted)
|
||||
stream.removeListener('data', onData)
|
||||
stream.removeListener('end', onEnd)
|
||||
stream.removeListener('error', onEnd)
|
||||
stream.removeListener('close', cleanup)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to require async_hooks
|
||||
* @private
|
||||
*/
|
||||
|
||||
function tryRequireAsyncHooks () {
|
||||
try {
|
||||
return require('async_hooks')
|
||||
} catch (e) {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap function with async resource, if possible.
|
||||
* AsyncResource.bind static method backported.
|
||||
* @private
|
||||
*/
|
||||
|
||||
function wrap (fn) {
|
||||
var res
|
||||
|
||||
// create anonymous resource
|
||||
if (asyncHooks.AsyncResource) {
|
||||
res = new asyncHooks.AsyncResource(fn.name || 'bound-anonymous-fn')
|
||||
}
|
||||
|
||||
// incompatible node.js
|
||||
if (!res || !res.runInAsyncScope) {
|
||||
return fn
|
||||
}
|
||||
|
||||
// return bound function
|
||||
return res.runInAsyncScope.bind(res, fn, null)
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
var colour = require('./colour');
|
||||
var bus = require('./bus');
|
||||
var required = false;
|
||||
var useColours = true;
|
||||
|
||||
var coding = {
|
||||
log: 'black',
|
||||
info: 'yellow',
|
||||
status: 'green',
|
||||
detail: 'yellow',
|
||||
fail: 'red',
|
||||
error: 'red',
|
||||
};
|
||||
|
||||
function log(type, text) {
|
||||
var msg = '[nodemon] ' + (text || '');
|
||||
|
||||
if (useColours) {
|
||||
msg = colour(coding[type], msg);
|
||||
}
|
||||
|
||||
// always push the message through our bus, using nextTick
|
||||
// to help testing and get _out of_ promises.
|
||||
process.nextTick(() => {
|
||||
bus.emit('log', { type: type, message: text, colour: msg });
|
||||
});
|
||||
|
||||
// but if we're running on the command line, also echo out
|
||||
// question: should we actually just consume our own events?
|
||||
if (!required) {
|
||||
if (type === 'error') {
|
||||
console.error(msg);
|
||||
} else {
|
||||
console.log(msg || '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var Logger = function (r) {
|
||||
if (!(this instanceof Logger)) {
|
||||
return new Logger(r);
|
||||
}
|
||||
this.required(r);
|
||||
return this;
|
||||
};
|
||||
|
||||
Object.keys(coding).forEach(function (type) {
|
||||
Logger.prototype[type] = log.bind(null, type);
|
||||
});
|
||||
|
||||
// detail is for messages that are turned on during debug
|
||||
Logger.prototype.detail = function (msg) {
|
||||
if (this.debug) {
|
||||
log('detail', msg);
|
||||
}
|
||||
};
|
||||
|
||||
Logger.prototype.required = function (val) {
|
||||
required = val;
|
||||
};
|
||||
|
||||
Logger.prototype.debug = false;
|
||||
Logger.prototype._log = function (type, msg) {
|
||||
if (required) {
|
||||
bus.emit('log', { type: type, message: msg || '', colour: msg || '' });
|
||||
} else if (type === 'error') {
|
||||
console.error(msg);
|
||||
} else {
|
||||
console.log(msg || '');
|
||||
}
|
||||
};
|
||||
|
||||
Object.defineProperty(Logger.prototype, 'useColours', {
|
||||
set: function (val) {
|
||||
useColours = val;
|
||||
},
|
||||
get: function () {
|
||||
return useColours;
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = Logger;
|
||||
@@ -0,0 +1,187 @@
|
||||
# is-number [](https://www.npmjs.com/package/is-number) [](https://npmjs.org/package/is-number) [](https://npmjs.org/package/is-number) [](https://travis-ci.org/jonschlinkert/is-number)
|
||||
|
||||
> Returns true if the value is a finite number.
|
||||
|
||||
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
|
||||
|
||||
## Install
|
||||
|
||||
Install with [npm](https://www.npmjs.com/):
|
||||
|
||||
```sh
|
||||
$ npm install --save is-number
|
||||
```
|
||||
|
||||
## Why is this needed?
|
||||
|
||||
In JavaScript, it's not always as straightforward as it should be to reliably check if a value is a number. It's common for devs to use `+`, `-`, or `Number()` to cast a string value to a number (for example, when values are returned from user input, regex matches, parsers, etc). But there are many non-intuitive edge cases that yield unexpected results:
|
||||
|
||||
```js
|
||||
console.log(+[]); //=> 0
|
||||
console.log(+''); //=> 0
|
||||
console.log(+' '); //=> 0
|
||||
console.log(typeof NaN); //=> 'number'
|
||||
```
|
||||
|
||||
This library offers a performant way to smooth out edge cases like these.
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const isNumber = require('is-number');
|
||||
```
|
||||
|
||||
See the [tests](./test.js) for more examples.
|
||||
|
||||
### true
|
||||
|
||||
```js
|
||||
isNumber(5e3); // true
|
||||
isNumber(0xff); // true
|
||||
isNumber(-1.1); // true
|
||||
isNumber(0); // true
|
||||
isNumber(1); // true
|
||||
isNumber(1.1); // true
|
||||
isNumber(10); // true
|
||||
isNumber(10.10); // true
|
||||
isNumber(100); // true
|
||||
isNumber('-1.1'); // true
|
||||
isNumber('0'); // true
|
||||
isNumber('012'); // true
|
||||
isNumber('0xff'); // true
|
||||
isNumber('1'); // true
|
||||
isNumber('1.1'); // true
|
||||
isNumber('10'); // true
|
||||
isNumber('10.10'); // true
|
||||
isNumber('100'); // true
|
||||
isNumber('5e3'); // true
|
||||
isNumber(parseInt('012')); // true
|
||||
isNumber(parseFloat('012')); // true
|
||||
```
|
||||
|
||||
### False
|
||||
|
||||
Everything else is false, as you would expect:
|
||||
|
||||
```js
|
||||
isNumber(Infinity); // false
|
||||
isNumber(NaN); // false
|
||||
isNumber(null); // false
|
||||
isNumber(undefined); // false
|
||||
isNumber(''); // false
|
||||
isNumber(' '); // false
|
||||
isNumber('foo'); // false
|
||||
isNumber([1]); // false
|
||||
isNumber([]); // false
|
||||
isNumber(function () {}); // false
|
||||
isNumber({}); // false
|
||||
```
|
||||
|
||||
## Release history
|
||||
|
||||
### 7.0.0
|
||||
|
||||
* Refactor. Now uses `.isFinite` if it exists.
|
||||
* Performance is about the same as v6.0 when the value is a string or number. But it's now 3x-4x faster when the value is not a string or number.
|
||||
|
||||
### 6.0.0
|
||||
|
||||
* Optimizations, thanks to @benaadams.
|
||||
|
||||
### 5.0.0
|
||||
|
||||
**Breaking changes**
|
||||
|
||||
* removed support for `instanceof Number` and `instanceof String`
|
||||
|
||||
## Benchmarks
|
||||
|
||||
As with all benchmarks, take these with a grain of salt. See the [benchmarks](./benchmark/index.js) for more detail.
|
||||
|
||||
```
|
||||
# all
|
||||
v7.0 x 413,222 ops/sec ±2.02% (86 runs sampled)
|
||||
v6.0 x 111,061 ops/sec ±1.29% (85 runs sampled)
|
||||
parseFloat x 317,596 ops/sec ±1.36% (86 runs sampled)
|
||||
fastest is 'v7.0'
|
||||
|
||||
# string
|
||||
v7.0 x 3,054,496 ops/sec ±1.05% (89 runs sampled)
|
||||
v6.0 x 2,957,781 ops/sec ±0.98% (88 runs sampled)
|
||||
parseFloat x 3,071,060 ops/sec ±1.13% (88 runs sampled)
|
||||
fastest is 'parseFloat,v7.0'
|
||||
|
||||
# number
|
||||
v7.0 x 3,146,895 ops/sec ±0.89% (89 runs sampled)
|
||||
v6.0 x 3,214,038 ops/sec ±1.07% (89 runs sampled)
|
||||
parseFloat x 3,077,588 ops/sec ±1.07% (87 runs sampled)
|
||||
fastest is 'v6.0'
|
||||
```
|
||||
|
||||
## About
|
||||
|
||||
<details>
|
||||
<summary><strong>Contributing</strong></summary>
|
||||
|
||||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Running Tests</strong></summary>
|
||||
|
||||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
|
||||
|
||||
```sh
|
||||
$ npm install && npm test
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Building docs</strong></summary>
|
||||
|
||||
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
|
||||
|
||||
To generate the readme, run the following command:
|
||||
|
||||
```sh
|
||||
$ npm install -g verbose/verb#dev verb-generate-readme && verb
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### Related projects
|
||||
|
||||
You might also be interested in these projects:
|
||||
|
||||
* [is-plain-object](https://www.npmjs.com/package/is-plain-object): Returns true if an object was created by the `Object` constructor. | [homepage](https://github.com/jonschlinkert/is-plain-object "Returns true if an object was created by the `Object` constructor.")
|
||||
* [is-primitive](https://www.npmjs.com/package/is-primitive): Returns `true` if the value is a primitive. | [homepage](https://github.com/jonschlinkert/is-primitive "Returns `true` if the value is a primitive. ")
|
||||
* [isobject](https://www.npmjs.com/package/isobject): Returns true if the value is an object and not an array or null. | [homepage](https://github.com/jonschlinkert/isobject "Returns true if the value is an object and not an array or null.")
|
||||
* [kind-of](https://www.npmjs.com/package/kind-of): Get the native type of a value. | [homepage](https://github.com/jonschlinkert/kind-of "Get the native type of a value.")
|
||||
|
||||
### Contributors
|
||||
|
||||
| **Commits** | **Contributor** |
|
||||
| --- | --- |
|
||||
| 49 | [jonschlinkert](https://github.com/jonschlinkert) |
|
||||
| 5 | [charlike-old](https://github.com/charlike-old) |
|
||||
| 1 | [benaadams](https://github.com/benaadams) |
|
||||
| 1 | [realityking](https://github.com/realityking) |
|
||||
|
||||
### Author
|
||||
|
||||
**Jon Schlinkert**
|
||||
|
||||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
|
||||
* [GitHub Profile](https://github.com/jonschlinkert)
|
||||
* [Twitter Profile](https://twitter.com/jonschlinkert)
|
||||
|
||||
### License
|
||||
|
||||
Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
|
||||
Released under the [MIT License](LICENSE).
|
||||
|
||||
***
|
||||
|
||||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on June 15, 2018._
|
||||
Reference in New Issue
Block a user