Comparing version 5.1.0 to 5.2.0
@@ -47,3 +47,9 @@ # Authors | ||
- Sam Sudar (sudar.sam@gmail.com) | ||
- Volker Mische (volker.mische@gmail.com) | ||
- David Walton (support@geekstocks.com) | ||
- Сковорода Никита Андреевич (chalkerx@gmail.com) | ||
- greenkeeper[bot] (greenkeeper[bot]@users.noreply.github.com) | ||
- ukstv (sergey.ukustov@machinomy.com) | ||
- ranbochen (ranbochen@qq.com) | ||
#### Generated by bin/update-authors.sh. |
145
index.js
@@ -57,6 +57,5 @@ /*! | ||
Object.defineProperty(Buffer.prototype, 'parent', { | ||
enumerable: true, | ||
get: function () { | ||
if (!(this instanceof Buffer)) { | ||
return undefined | ||
} | ||
if (!Buffer.isBuffer(this)) return undefined | ||
return this.buffer | ||
@@ -67,6 +66,5 @@ } | ||
Object.defineProperty(Buffer.prototype, 'offset', { | ||
enumerable: true, | ||
get: function () { | ||
if (!(this instanceof Buffer)) { | ||
return undefined | ||
} | ||
if (!Buffer.isBuffer(this)) return undefined | ||
return this.byteOffset | ||
@@ -78,3 +76,3 @@ } | ||
if (length > K_MAX_LENGTH) { | ||
throw new RangeError('Invalid typed array length') | ||
throw new RangeError('The value "' + length + '" is invalid for option "size"') | ||
} | ||
@@ -101,4 +99,4 @@ // Return an augmented `Uint8Array` instance | ||
if (typeof encodingOrOffset === 'string') { | ||
throw new Error( | ||
'If encoding is specified then the first argument must be a string' | ||
throw new TypeError( | ||
'The "string" argument must be of type string. Received type number' | ||
) | ||
@@ -112,3 +110,3 @@ } | ||
// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 | ||
if (typeof Symbol !== 'undefined' && Symbol.species && | ||
if (typeof Symbol !== 'undefined' && Symbol.species != null && | ||
Buffer[Symbol.species] === Buffer) { | ||
@@ -126,15 +124,47 @@ Object.defineProperty(Buffer, Symbol.species, { | ||
function from (value, encodingOrOffset, length) { | ||
if (typeof value === 'number') { | ||
throw new TypeError('"value" argument must not be a number') | ||
if (typeof value === 'string') { | ||
return fromString(value, encodingOrOffset) | ||
} | ||
if (isArrayBuffer(value) || (value && isArrayBuffer(value.buffer))) { | ||
if (ArrayBuffer.isView(value)) { | ||
return fromArrayLike(value) | ||
} | ||
if (value == null) { | ||
throw TypeError( | ||
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + | ||
'or Array-like Object. Received type ' + (typeof value) | ||
) | ||
} | ||
if (isInstance(value, ArrayBuffer) || | ||
(value && isInstance(value.buffer, ArrayBuffer))) { | ||
return fromArrayBuffer(value, encodingOrOffset, length) | ||
} | ||
if (typeof value === 'string') { | ||
return fromString(value, encodingOrOffset) | ||
if (typeof value === 'number') { | ||
throw new TypeError( | ||
'The "value" argument must not be of type number. Received type number' | ||
) | ||
} | ||
return fromObject(value) | ||
var valueOf = value.valueOf && value.valueOf() | ||
if (valueOf != null && valueOf !== value) { | ||
return Buffer.from(valueOf, encodingOrOffset, length) | ||
} | ||
var b = fromObject(value) | ||
if (b) return b | ||
if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && | ||
typeof value[Symbol.toPrimitive] === 'function') { | ||
return Buffer.from( | ||
value[Symbol.toPrimitive]('string'), encodingOrOffset, length | ||
) | ||
} | ||
throw new TypeError( | ||
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + | ||
'or Array-like Object. Received type ' + (typeof value) | ||
) | ||
} | ||
@@ -163,3 +193,3 @@ | ||
} else if (size < 0) { | ||
throw new RangeError('"size" argument must not be negative') | ||
throw new RangeError('The value "' + size + '" is invalid for option "size"') | ||
} | ||
@@ -279,16 +309,12 @@ } | ||
if (obj) { | ||
if (ArrayBuffer.isView(obj) || 'length' in obj) { | ||
if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { | ||
return createBuffer(0) | ||
} | ||
return fromArrayLike(obj) | ||
if (obj.length !== undefined) { | ||
if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { | ||
return createBuffer(0) | ||
} | ||
return fromArrayLike(obj) | ||
} | ||
if (obj.type === 'Buffer' && Array.isArray(obj.data)) { | ||
return fromArrayLike(obj.data) | ||
} | ||
if (obj.type === 'Buffer' && Array.isArray(obj.data)) { | ||
return fromArrayLike(obj.data) | ||
} | ||
throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object.') | ||
} | ||
@@ -314,8 +340,13 @@ | ||
Buffer.isBuffer = function isBuffer (b) { | ||
return b != null && b._isBuffer === true | ||
return b != null && b._isBuffer === true && | ||
b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false | ||
} | ||
Buffer.compare = function compare (a, b) { | ||
if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength) | ||
if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength) | ||
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { | ||
throw new TypeError('Arguments must be Buffers') | ||
throw new TypeError( | ||
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array' | ||
) | ||
} | ||
@@ -381,3 +412,3 @@ | ||
var buf = list[i] | ||
if (ArrayBuffer.isView(buf)) { | ||
if (isInstance(buf, Uint8Array)) { | ||
buf = Buffer.from(buf) | ||
@@ -398,11 +429,15 @@ } | ||
} | ||
if (ArrayBuffer.isView(string) || isArrayBuffer(string)) { | ||
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) { | ||
return string.byteLength | ||
} | ||
if (typeof string !== 'string') { | ||
string = '' + string | ||
throw new TypeError( | ||
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + | ||
'Received type ' + typeof string | ||
) | ||
} | ||
var len = string.length | ||
if (len === 0) return 0 | ||
var mustMatch = (arguments.length > 2 && arguments[2] === true) | ||
if (!mustMatch && len === 0) return 0 | ||
@@ -419,3 +454,2 @@ // Use a for loop to avoid recursion | ||
case 'utf-8': | ||
case undefined: | ||
return utf8ToBytes(string).length | ||
@@ -432,3 +466,5 @@ case 'ucs2': | ||
default: | ||
if (loweredCase) return utf8ToBytes(string).length // assume utf8 | ||
if (loweredCase) { | ||
return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8 | ||
} | ||
encoding = ('' + encoding).toLowerCase() | ||
@@ -580,6 +616,4 @@ loweredCase = true | ||
var max = exports.INSPECT_MAX_BYTES | ||
if (this.length > 0) { | ||
str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') | ||
if (this.length > max) str += ' ... ' | ||
} | ||
str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim() | ||
if (this.length > max) str += ' ... ' | ||
return '<Buffer ' + str + '>' | ||
@@ -589,4 +623,10 @@ } | ||
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { | ||
if (isInstance(target, Uint8Array)) { | ||
target = Buffer.from(target, target.offset, target.byteLength) | ||
} | ||
if (!Buffer.isBuffer(target)) { | ||
throw new TypeError('Argument must be a Buffer') | ||
throw new TypeError( | ||
'The "target" argument must be one of type Buffer or Uint8Array. ' + | ||
'Received type ' + (typeof target) | ||
) | ||
} | ||
@@ -670,3 +710,3 @@ | ||
} | ||
byteOffset = +byteOffset // Coerce to Number. | ||
byteOffset = +byteOffset // Coerce to Number. | ||
if (numberIsNaN(byteOffset)) { | ||
@@ -923,4 +963,4 @@ // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer | ||
: (firstByte > 0xDF) ? 3 | ||
: (firstByte > 0xBF) ? 2 | ||
: 1 | ||
: (firstByte > 0xBF) ? 2 | ||
: 1 | ||
@@ -1588,3 +1628,3 @@ if (i + bytesPerSequence <= end) { | ||
? val | ||
: new Buffer(val, encoding) | ||
: Buffer.from(val, encoding) | ||
var len = bytes.length | ||
@@ -1744,12 +1784,13 @@ if (len === 0) { | ||
// ArrayBuffers from another context (i.e. an iframe) do not pass the `instanceof` check | ||
// but they should be treated as valid. See: https://github.com/feross/buffer/issues/166 | ||
function isArrayBuffer (obj) { | ||
return obj instanceof ArrayBuffer || | ||
(obj != null && obj.constructor != null && obj.constructor.name === 'ArrayBuffer' && | ||
typeof obj.byteLength === 'number') | ||
// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass | ||
// the `instanceof` check but they should be treated as of that type. | ||
// See: https://github.com/feross/buffer/issues/166 | ||
function isInstance (obj, type) { | ||
return obj instanceof type || | ||
(obj != null && obj.constructor != null && obj.constructor.name != null && | ||
obj.constructor.name === type.name) | ||
} | ||
function numberIsNaN (obj) { | ||
// For IE11 support | ||
return obj !== obj // eslint-disable-line no-self-compare | ||
} |
{ | ||
"name": "buffer", | ||
"description": "Node.js Buffer API, for the browser", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"author": { | ||
@@ -22,7 +22,8 @@ "name": "Feross Aboukhadijeh", | ||
"devDependencies": { | ||
"airtap": "0.1.0", | ||
"benchmark": "^2.0.0", | ||
"browserify": "^14.0.0", | ||
"browserify": "^16.1.0", | ||
"concat-stream": "^1.4.7", | ||
"hyperquest": "^2.0.0", | ||
"is-buffer": "^1.1.1", | ||
"is-buffer": "^2.0.0", | ||
"is-nan": "^1.0.1", | ||
@@ -33,4 +34,3 @@ "split": "^1.0.0", | ||
"through2": "^2.0.0", | ||
"uglify-js": "^2.7.3", | ||
"zuul": "^3.0.0" | ||
"uglify-js": "^3.3.12" | ||
}, | ||
@@ -56,2 +56,3 @@ "homepage": "https://github.com/feross/buffer", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"repository": { | ||
@@ -66,6 +67,6 @@ "type": "git", | ||
"test": "standard && node ./bin/test.js", | ||
"test-browser-es5": "zuul --ui tape -- test/*.js", | ||
"test-browser-es5-local": "zuul --ui tape --local -- test/*.js", | ||
"test-browser-es6": "zuul --ui tape -- test/*.js test/node/*.js", | ||
"test-browser-es6-local": "zuul --ui tape --local -- test/*.js test/node/*.js", | ||
"test-browser-es5": "airtap -- test/*.js", | ||
"test-browser-es5-local": "airtap --local -- test/*.js", | ||
"test-browser-es6": "airtap -- test/*.js test/node/*.js", | ||
"test-browser-es6-local": "airtap --local -- test/*.js test/node/*.js", | ||
"test-node": "tape test/*.js test/node/*.js", | ||
@@ -72,0 +73,0 @@ "update-authors": "./bin/update-authors.sh" |
@@ -384,3 +384,3 @@ # buffer [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url] | ||
This will print out a URL that you can then open in a browser to run the tests, using [Zuul](https://github.com/defunctzombie/zuul). | ||
This will print out a URL that you can then open in a browser to run the tests, using [airtap](https://www.npmjs.com/package/airtap). | ||
@@ -391,3 +391,3 @@ To run automated browser tests using Saucelabs, ensure that your `SAUCE_USERNAME` and `SAUCE_ACCESS_KEY` environment variables are set, then run: | ||
This is what's run in Travis, to check against various browsers. The list of browsers is kept in the `.zuul.yml` file. | ||
This is what's run in Travis, to check against various browsers. The list of browsers is kept in the `bin/airtap-es5.yml` and `bin/airtap-es6.yml` files. | ||
@@ -394,0 +394,0 @@ ## JavaScript Standard Style |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
0
80664
6
1709
1