buffer-indexof-polyfill
Advanced tools
Comparing version 1.0.1 to 1.0.2
11
index.js
"use strict"; | ||
var initBuffer = require("./init-buffer"); | ||
@@ -10,5 +11,5 @@ if (!Buffer.prototype.indexOf) { | ||
if (typeof value === "string" || value instanceof String) { | ||
value = new Buffer(value); | ||
value = initBuffer(value); | ||
} else if (typeof value === "number" || value instanceof Number) { | ||
value = new Buffer([ value ]); | ||
value = initBuffer([ value ]); | ||
} | ||
@@ -41,5 +42,5 @@ | ||
if (typeof value === "string" || value instanceof String) { | ||
value = new Buffer(value); | ||
value = initBuffer(value); | ||
} else if (typeof value === "number" || value instanceof Number) { | ||
value = new Buffer([ value ]); | ||
value = initBuffer([ value ]); | ||
} | ||
@@ -70,3 +71,3 @@ | ||
// check Buffer#lastIndexOf is usable: https://github.com/nodejs/node/issues/4604 | ||
if (new Buffer ("ABC").lastIndexOf ("ABC") === -1) | ||
if (initBuffer("ABC").lastIndexOf ("ABC") === -1) | ||
Buffer.prototype.lastIndexOf = bufferLastIndexOf; | ||
@@ -73,0 +74,0 @@ } else { |
{ | ||
"name": "buffer-indexof-polyfill", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "This is a polyfill for Buffer#indexOf introduced in NodeJS 4.0.", | ||
@@ -8,3 +8,4 @@ "main": "index.js", | ||
"test": "mocha", | ||
"lint": "eslint ." | ||
"lint": "eslint .", | ||
"fix": "eslint . --fix" | ||
}, | ||
@@ -11,0 +12,0 @@ "author": "https://github.com/sarosia", |
"use strict"; | ||
var expect = require("chai").expect; | ||
var initBuffer = require("../init-buffer"); | ||
require("../index.js"); | ||
@@ -9,22 +11,21 @@ | ||
it("Buffer as value", function () { | ||
var buffer = new Buffer("ABC"); | ||
var buffer = initBuffer("ABC"); | ||
expect(buffer.indexOf(new Buffer("ABC"))).to.be.equal(0); | ||
expect(buffer.indexOf(new Buffer("AB"))).to.be.equal(0); | ||
expect(buffer.indexOf(new Buffer("BC"))).to.be.equal(1); | ||
expect(buffer.indexOf(new Buffer("C"))).to.be.equal(2); | ||
expect(buffer.indexOf(new Buffer("CC"))).to.be.equal(-1); | ||
expect(buffer.indexOf(new Buffer("CA"))).to.be.equal(-1); | ||
expect(buffer.indexOf(initBuffer("ABC"))).to.be.equal(0); | ||
expect(buffer.indexOf(initBuffer("AB"))).to.be.equal(0); | ||
expect(buffer.indexOf(initBuffer("BC"))).to.be.equal(1); | ||
expect(buffer.indexOf(initBuffer("C"))).to.be.equal(2); | ||
expect(buffer.indexOf(initBuffer("CC"))).to.be.equal(-1); | ||
expect(buffer.indexOf(initBuffer("CA"))).to.be.equal(-1); | ||
expect(buffer.indexOf(new Buffer("ABC"), 1)).to.be.equal(-1); | ||
expect(buffer.indexOf(new Buffer("AB"), 1)).to.be.equal(-1); | ||
expect(buffer.indexOf(new Buffer("BC"), 1)).to.be.equal(1); | ||
expect(buffer.indexOf(new Buffer("C"), 1)).to.be.equal(2); | ||
expect(buffer.indexOf(new Buffer("CC"), 1)).to.be.equal(-1); | ||
expect(buffer.indexOf(new Buffer("CA"), 1)).to.be.equal(-1); | ||
expect(buffer.indexOf(initBuffer("ABC"), 1)).to.be.equal(-1); | ||
expect(buffer.indexOf(initBuffer("AB"), 1)).to.be.equal(-1); | ||
expect(buffer.indexOf(initBuffer("BC"), 1)).to.be.equal(1); | ||
expect(buffer.indexOf(initBuffer("C"), 1)).to.be.equal(2); | ||
expect(buffer.indexOf(initBuffer("CC"), 1)).to.be.equal(-1); | ||
expect(buffer.indexOf(initBuffer("CA"), 1)).to.be.equal(-1); | ||
}); | ||
it("String as value", function () { | ||
var buffer = new Buffer("ABC"); | ||
var buffer = initBuffer("ABC"); | ||
expect(buffer.indexOf("ABC")).to.be.equal(0); | ||
@@ -46,4 +47,3 @@ expect(buffer.indexOf("AB")).to.be.equal(0); | ||
it("Number as value", function () { | ||
var buffer = new Buffer([ 1, 2, 3 ]); | ||
var buffer = initBuffer([ 1, 2, 3 ]); | ||
expect(buffer.indexOf(1)).to.be.equal(0); | ||
@@ -64,21 +64,21 @@ expect(buffer.indexOf(2)).to.be.equal(1); | ||
it("Buffer as value", function () { | ||
var buffer = new Buffer("ABCABC"); | ||
var buffer = initBuffer("ABCABC"); | ||
expect(buffer.lastIndexOf(new Buffer("ABC"))).to.be.equal(3); | ||
expect(buffer.lastIndexOf(new Buffer("AB"))).to.be.equal(3); | ||
expect(buffer.lastIndexOf(new Buffer("BC"))).to.be.equal(4); | ||
expect(buffer.lastIndexOf(new Buffer("C"))).to.be.equal(5); | ||
expect(buffer.lastIndexOf(new Buffer("CC"))).to.be.equal(-1); | ||
expect(buffer.lastIndexOf(new Buffer("CA"))).to.be.equal(2); | ||
expect(buffer.lastIndexOf(initBuffer("ABC"))).to.be.equal(3); | ||
expect(buffer.lastIndexOf(initBuffer("AB"))).to.be.equal(3); | ||
expect(buffer.lastIndexOf(initBuffer("BC"))).to.be.equal(4); | ||
expect(buffer.lastIndexOf(initBuffer("C"))).to.be.equal(5); | ||
expect(buffer.lastIndexOf(initBuffer("CC"))).to.be.equal(-1); | ||
expect(buffer.lastIndexOf(initBuffer("CA"))).to.be.equal(2); | ||
expect(buffer.lastIndexOf(new Buffer("ABC"), 1)).to.be.equal(0); | ||
expect(buffer.lastIndexOf(new Buffer("AB"), 1)).to.be.equal(0); | ||
expect(buffer.lastIndexOf(new Buffer("BC"), 1)).to.be.equal(1); | ||
expect(buffer.lastIndexOf(new Buffer("C"), 1)).to.be.equal(-1); | ||
expect(buffer.lastIndexOf(new Buffer("CC"), 1)).to.be.equal(-1); | ||
expect(buffer.lastIndexOf(new Buffer("CA"), 1)).to.be.equal(-1); | ||
expect(buffer.lastIndexOf(initBuffer("ABC"), 1)).to.be.equal(0); | ||
expect(buffer.lastIndexOf(initBuffer("AB"), 1)).to.be.equal(0); | ||
expect(buffer.lastIndexOf(initBuffer("BC"), 1)).to.be.equal(1); | ||
expect(buffer.lastIndexOf(initBuffer("C"), 1)).to.be.equal(-1); | ||
expect(buffer.lastIndexOf(initBuffer("CC"), 1)).to.be.equal(-1); | ||
expect(buffer.lastIndexOf(initBuffer("CA"), 1)).to.be.equal(-1); | ||
}); | ||
it("String as value", function () { | ||
var buffer = new Buffer("ABCABC"); | ||
var buffer = initBuffer("ABCABC"); | ||
@@ -119,3 +119,3 @@ expect(buffer.lastIndexOf("ABC")).to.be.equal(3); | ||
it("Number as value", function () { | ||
var buffer = new Buffer([ 1, 2, 3, 1, 2, 3]); | ||
var buffer = initBuffer([ 1, 2, 3, 1, 2, 3]); | ||
@@ -122,0 +122,0 @@ expect(buffer.lastIndexOf(1)).to.be.equal(3); |
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
11448
170