Comparing version 0.5.2 to 0.5.3
@@ -0,1 +1,4 @@ | ||
# es6-shim 0.5.3 (September 2, 2012) | ||
* Made `String#startsWith`, `String#endsWith` fully conform spec. | ||
# es6-shim 0.5.2 (June 17, 2012) | ||
@@ -2,0 +5,0 @@ * Removed `String#toArray` and `Object.isObject` as per spec updates. |
153
es6-shim.js
@@ -1,4 +0,8 @@ | ||
({define: (typeof define === 'function') | ||
? define // RequireJS | ||
: function(definition) {definition();} // CommonJS and <script> | ||
// ES6-shim 0.5.3 (c) 2012 Paul Miller (paulmillr.com) | ||
// ES6-shim may be freely distributed under the MIT license. | ||
// For more details and documentation: | ||
// https://github.com/paulmillr/es6-shim/ | ||
({define: (typeof define === 'function') ? | ||
define : // RequireJS | ||
function(definition) {definition();} // CommonJS and <script> | ||
}).define(function() { | ||
@@ -35,17 +39,92 @@ 'use strict'; | ||
defineProperties(String.prototype, { | ||
// Fast repeat, uses the `Exponentiation by squaring` algorithm. | ||
repeat: function(times) { | ||
return new Array(times + 1).join(this); | ||
if (times < 1) return ''; | ||
if (times % 2) return this.repeat(times - 1) + this; | ||
var half = this.repeat(times / 2); | ||
return half + half; | ||
}, | ||
startsWith: function(substring) { | ||
return this.lastIndexOf(substring, 0) === 0; | ||
startsWith: function(searchString) { | ||
var position = arguments[1]; | ||
// Let searchStr be ToString(searchString). | ||
var searchStr = searchString.toString(); | ||
// ReturnIfAbrupt(searchStr). | ||
// Let S be the result of calling ToString, | ||
// giving it the this value as its argument. | ||
var s = this.toString(); | ||
// ReturnIfAbrupt(S). | ||
// Let pos be ToInteger(position). | ||
// (If position is undefined, this step produces the value 0). | ||
var pos = (position === undefined) ? 0 : Number.toInteger(position); | ||
// ReturnIfAbrupt(pos). | ||
// Let len be the number of elements in S. | ||
var len = s.length; | ||
// Let start be min(max(pos, 0), len). | ||
var start = Math.min(Math.max(pos, 0), len); | ||
// Let searchLength be the number of elements in searchString. | ||
var searchLength = searchString.length; | ||
// If searchLength+start is greater than len, return false. | ||
if ((searchLength + start) > len) return false; | ||
// If the searchLength sequence of elements of S starting at | ||
// start is the same as the full element sequence of searchString, | ||
// return true. | ||
var index = ''.indexOf.call(s, searchString, start); | ||
return index === start; | ||
}, | ||
endsWith: function(substring) { | ||
var startFrom = this.length - String(substring).length; | ||
return startFrom >= 0 && this.indexOf(substring, startFrom) === startFrom; | ||
endsWith: function(searchString) { | ||
var endPosition = arguments[1]; | ||
// ReturnIfAbrupt(CheckObjectCoercible(this value)). | ||
// Let S be the result of calling ToString, giving it the this value as its argument. | ||
// ReturnIfAbrupt(S). | ||
var s = this.toString(); | ||
// Let searchStr be ToString(searchString). | ||
// ReturnIfAbrupt(searchStr). | ||
var searchStr = searchString.toString(); | ||
// Let len be the number of elements in S. | ||
var len = s.length; | ||
// If endPosition is undefined, let pos be len, else let pos be ToInteger(endPosition). | ||
// ReturnIfAbrupt(pos). | ||
var pos = (endPosition === undefined) ? | ||
len : | ||
Number.toInteger(endPosition); | ||
// Let end be min(max(pos, 0), len). | ||
var end = Math.min(Math.max(pos, 0), len); | ||
// Let searchLength be the number of elements in searchString. | ||
var searchLength = searchString.length; | ||
// Let start be end - searchLength. | ||
var start = end - searchLength; | ||
// If start is less than 0, return false. | ||
if (start < 0) return false; | ||
// If the searchLength sequence of elements of S starting at start is the same as the full element sequence of searchString, return true. | ||
// Otherwise, return false. | ||
var index = ''.indexOf.call(s, searchString, start); | ||
return index === start; | ||
}, | ||
contains: function(substring) { | ||
return this.indexOf(substring) !== -1; | ||
contains: function(searchString) { | ||
var position = arguments[1]; | ||
// Somehow this trick makes method 100% compat with the spec. | ||
return ''.indexOf.call(this, searchString, position) !== -1; | ||
} | ||
@@ -56,3 +135,3 @@ }); | ||
from: function(iterable) { | ||
var object = Object(iterable); | ||
var object = new Object(iterable); | ||
var array = []; | ||
@@ -132,12 +211,14 @@ | ||
getPropertyNames: function(subject, name) { | ||
getPropertyNames: function(subject) { | ||
var result = Object.getOwnPropertyNames(subject); | ||
var proto = Object.getPrototypeOf(subject); | ||
var property; | ||
var addProperty = function(property) { | ||
if (result.indexOf(property) === -1) { | ||
result.push(property); | ||
} | ||
}; | ||
while (proto !== null) { | ||
Object.getOwnPropertyNames(proto).forEach(function(property) { | ||
if (result.indexOf(property) === -1) { | ||
result.push(property); | ||
} | ||
}); | ||
Object.getOwnPropertyNames(proto).forEach(addProperty); | ||
proto = Object.getPrototypeOf(proto); | ||
@@ -150,3 +231,3 @@ } | ||
if (x === y) { | ||
// 0 === -0, but they are not identical | ||
// 0 === -0, but they are not identical. | ||
if (x === 0) { | ||
@@ -163,11 +244,11 @@ return 1 / x === 1 / y; | ||
// isNaN is broken: it converts its argument to number, so | ||
// isNaN("foo") => true | ||
// isNaN('foo') => true | ||
return x !== x && y !== y; | ||
}, | ||
isnt: function(x, y) { | ||
return !Object.is(x, y); | ||
} | ||
}); | ||
}); | ||
defineProperties(Math, { | ||
@@ -177,7 +258,7 @@ acosh: function(value) { | ||
}, | ||
asinh: function(value) { | ||
return Math.log(value + Math.sqrt(value * value + 1)); | ||
}, | ||
atanh: function(value) { | ||
@@ -192,3 +273,3 @@ return 0.5 * Math.log((1 + value) / (1 - value)); | ||
}, | ||
expm1: function(value) { | ||
@@ -202,3 +283,3 @@ var result = 0; | ||
}, | ||
hypot: function(x, y) { | ||
@@ -211,7 +292,7 @@ return Math.sqrt(x * x + y * y) || 0; | ||
}, | ||
log10: function(value) { | ||
return Math.log(value) * (1 / Math.LN10); | ||
}, | ||
log1p: function(value) { | ||
@@ -240,11 +321,11 @@ var result = 0; | ||
}, | ||
sinh: function(value) { | ||
return (Math.exp(value) - Math.exp(-value)) / 2; | ||
}, | ||
tanh: function(value) { | ||
return (Math.exp(value) - Math.exp(-value)) / (Math.exp(value) + Math.exp(-value)); | ||
}, | ||
trunc: function(value) { | ||
@@ -265,3 +346,3 @@ return ~~value; | ||
function Map() { | ||
if (!(this instanceof Map)) return new Map; | ||
if (!(this instanceof Map)) return new Map(); | ||
defineProperty(this, 'keys', []); | ||
@@ -306,4 +387,4 @@ defineProperty(this, 'values', []); | ||
function Set() { | ||
if (!(this instanceof Set)) return new Set; | ||
defineProperty(this, 'map', Map()); | ||
if (!(this instanceof Set)) return new Set(); | ||
defineProperty(this, 'map', new Map()); | ||
} | ||
@@ -310,0 +391,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "ECMAScript 6 (Harmony) compatibility shims for legacy JavaScript engines", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"homepage": "https://github.com/paulmillr/es6-shim/", | ||
@@ -14,3 +14,3 @@ "repository": { | ||
"scripts": { | ||
"test": "./node_modules/mocha/bin/mocha --reporter spec --require 'test/test_helpers.js'" | ||
"test": "mocha --require 'test/test_helpers.js'" | ||
}, | ||
@@ -17,0 +17,0 @@ "engines": { |
@@ -19,3 +19,3 @@ describe('Array', function() { | ||
}); | ||
describe('Array.of()', function() { | ||
@@ -22,0 +22,0 @@ it('should create correct array from arguments', function() { |
@@ -12,3 +12,3 @@ // Big thanks to V8 folks for test ideas. | ||
}; | ||
var expectNotEnumerable = function(object) { | ||
@@ -28,3 +28,3 @@ expect(Object.keys(object).length).to.equal(0); | ||
}); | ||
afterEach(function() { | ||
@@ -46,3 +46,3 @@ map = null; | ||
it('should map values correctly', function() { | ||
it('should map values correctly', function() { | ||
range(1, 20).forEach(function(number) { | ||
@@ -53,3 +53,3 @@ testMapping(number, new Object); | ||
}); | ||
[+0, -0, Infinity, -Infinity, true, false, null, undefined].forEach(function(key) { | ||
@@ -59,3 +59,3 @@ testMapping(key, new Object); | ||
}); | ||
it('should has correct querying behavior', function() { | ||
@@ -70,7 +70,7 @@ var key = new Object; | ||
}); | ||
it('should allow to be initialized directly', function() { | ||
expect(Map()).to.be.an.instanceof(Map); | ||
}); | ||
it('should allow NaN values as keys', function() { | ||
@@ -85,3 +85,3 @@ expect(map.has(NaN)).to.be.false; | ||
}); | ||
it('should not have [[Enumerable]] props', function() { | ||
@@ -92,3 +92,3 @@ expectNotEnumerable(Map); | ||
}); | ||
it('should allow common ecmascript idioms', function() { | ||
@@ -101,3 +101,3 @@ expect(map).to.be.an.instanceof(Map); | ||
}); | ||
it('should has unique constructor', function() { | ||
@@ -114,3 +114,3 @@ expect(Map.prototype).to.not.equal(Object.prototype); | ||
}); | ||
afterEach(function() { | ||
@@ -123,3 +123,3 @@ set = null; | ||
}); | ||
it('should has valid getter and setter calls', function() { | ||
@@ -132,3 +132,3 @@ ['add', 'has', 'delete'].forEach(function(method) { | ||
}); | ||
it('should work as expected', function() { | ||
@@ -142,3 +142,3 @@ var testSet = function(key) { | ||
}; | ||
range(1, 20).forEach(function(number) { | ||
@@ -150,10 +150,10 @@ testSet(new Object); | ||
}); | ||
[+0, -0, Infinity, -Infinity, true, false, null, undefined].forEach(testSet); | ||
}); | ||
it('should allow to be initialized directly', function() { | ||
expect(Set()).to.be.an.instanceof(Set); | ||
}); | ||
it('should allow NaN values as keys', function() { | ||
@@ -168,3 +168,3 @@ expect(set.has(NaN)).to.be.false; | ||
}); | ||
it('should not have [[Enumerable]] props', function() { | ||
@@ -182,12 +182,12 @@ expectNotEnumerable(Set); | ||
}); | ||
it('should has unique constructor', function() { | ||
expect(Set.prototype).to.not.equal(Object.prototype); | ||
}); | ||
it('should throw proper errors when user invokes methods with wrong types of receiver', | ||
function() { | ||
}); | ||
}); | ||
}); |
@@ -17,3 +17,3 @@ describe('Number', function() { | ||
}); | ||
it('should has epsilon', function() { | ||
@@ -40,4 +40,30 @@ expect(Number.EPSILON).to.equal(2.220446049250313e-16); | ||
infinities.map(Number.isFinite).forEach(expectToNotBeOk); | ||
expect(Number.isFinite(Infinity)).to.not.be.ok | ||
expect(Number.isFinite(-Infinity)).to.not.be.ok; | ||
expect(Number.isFinite(NaN)).to.not.be.ok; | ||
expect(Number.isFinite(4)).to.be.ok; | ||
expect(Number.isFinite(4.5)).to.be.ok; | ||
expect(Number.isFinite('hi')).to.not.be.ok; | ||
expect(Number.isFinite('1.3')).to.not.be.ok; | ||
expect(Number.isFinite('51')).to.not.be.ok; | ||
expect(Number.isFinite(0)).to.be.ok; | ||
expect(Number.isFinite(-0)).to.be.ok; | ||
expect(Number.isFinite({ | ||
valueOf: function() { return 3; } | ||
})).to.not.be.ok; | ||
expect(Number.isFinite({ | ||
valueOf: function() { return 0/0; } | ||
})).to.not.be.ok; | ||
expect(Number.isFinite({ | ||
valueOf: function() { throw 17; } | ||
})).to.not.be.ok; | ||
expect(Number.isFinite({ | ||
toString: function() { throw 17; } | ||
})).to.not.be.ok; | ||
expect(Number.isFinite({ | ||
valueOf: function() { throw 17; }, | ||
toString: function() { throw 42; } | ||
})).to.not.be.ok; | ||
}); | ||
it('should not be confused by type coercion', function() { | ||
@@ -51,9 +77,31 @@ nonNumbers.map(Number.isFinite).forEach(expectToNotBeOk); | ||
integers.map(Number.isInteger).forEach(expectToBeOk); | ||
expect(Number.isInteger(4)).to.be.ok; | ||
expect(Number.isInteger(4.)).to.be.ok; | ||
expect(Number.isInteger(4.2)).to.not.be.ok; | ||
expect(Number.isInteger(0.)).to.be.ok; | ||
expect(Number.isInteger(-0.)).to.be.ok; | ||
expect(Number.isInteger(Infinity)).to.not.be.ok; | ||
expect(Number.isInteger(-Infinity)).to.not.be.ok; | ||
expect(Number.isInteger(NaN)).to.not.be.ok; | ||
expect(Number.isInteger(true)).to.not.be.ok; | ||
expect(Number.isInteger(false)).to.not.be.ok; | ||
expect(Number.isInteger('str')).to.not.be.ok; | ||
expect(Number.isInteger({})).to.not.be.ok; | ||
expect(Number.isInteger({ | ||
valueOf: function() { return 3; } | ||
})).to.not.be.ok; | ||
expect(Number.isInteger({ | ||
valueOf: function() { return 0/0; } | ||
})).to.not.be.ok; | ||
expect(Number.isInteger({ | ||
valueOf: function() { throw 17; } | ||
})).to.not.be.ok; | ||
expect(Number.isInteger({ | ||
toString: function() { throw 17; } | ||
})).to.not.be.ok; | ||
expect(Number.isInteger({ | ||
valueOf: function() { throw 17; }, | ||
toString: function() { throw 42; } | ||
})).to.not.be.ok; | ||
}); | ||
it('should not be confused by type coercion', function() { | ||
nonIntegers.concat( | ||
infinities, nonNumbers | ||
).map(Number.isInteger).forEach(expectToNotBeOk); | ||
}); | ||
}); | ||
@@ -63,8 +111,22 @@ | ||
it('should be truthy only on NaN', function() { | ||
expect(Number.isNaN(NaN)).to.be.ok; | ||
integers.concat(nonIntegers).map(Number.isNaN).forEach(expectToNotBeOk); | ||
}); | ||
it('should not be confused by type coercion', function() { | ||
nonNumbers.map(Number.isNaN).forEach(expectToNotBeOk); | ||
expect(Number.isNaN(NaN)).to.be.ok; | ||
expect(Number.isNaN(0/0)).to.be.ok; | ||
expect(Number.isNaN(Number('NaN'))).to.be.ok; | ||
expect(Number.isNaN(4)).to.not.be.ok; | ||
expect(Number.isNaN(4.5)).to.not.be.ok; | ||
expect(Number.isNaN('hi')).to.not.be.ok; | ||
expect(Number.isNaN('1.3')).to.not.be.ok; | ||
expect(Number.isNaN('51')).to.not.be.ok; | ||
expect(Number.isNaN(0)).to.not.be.ok; | ||
expect(Number.isNaN(-0)).to.not.be.ok; | ||
expect(Number.isNaN({valueOf: function() { return 3; }})).to.not.be.ok; | ||
expect(Number.isNaN({valueOf: function() { return 0/0; }})).to.not.be.ok; | ||
expect(Number.isNaN({valueOf: function() { throw 17; } })).to.not.be.ok; | ||
expect(Number.isNaN({toString: function() { throw 17; } })).to.not.be.ok; | ||
expect(Number.isNaN({ | ||
valueOf: function() { throw 17; }, | ||
toString: function() { throw 42; } | ||
})).to.not.be.ok; | ||
}); | ||
@@ -75,9 +137,30 @@ }); | ||
it('should convert things to integer value', function() { | ||
integers.concat(infinities).forEach(function(item) { | ||
expect(Number.toInteger(item)).to.equal(item); | ||
}); | ||
[[1.5, 1], [-1.5, -1], [1/3, 0], [NaN, 0], ['str', 0] | ||
].forEach(function(item) { | ||
expect(Number.toInteger(item[0])).to.equal(item[1]); | ||
}); | ||
expect(Number.toInteger(4)).to.equal(4); | ||
expect(Number.toInteger(4.)).to.equal(4); | ||
expect(Number.toInteger(4.3)).to.equal(4); | ||
expect(Number.toInteger(-4)).to.equal(-4); | ||
expect(Number.toInteger(-4.)).to.equal(-4); | ||
expect(Number.toInteger(-4.3)).to.equal(-4); | ||
expect(Number.toInteger(0.)).to.equal(0.); | ||
expect(Number.toInteger(-0.)).to.equal(-0.); | ||
expect(Number.toInteger(Infinity)).to.equal(Infinity); | ||
expect(Number.toInteger(-Infinity)).to.equal(-Infinity); | ||
expect(Number.toInteger(NaN)).to.equal(0); | ||
expect(Number.toInteger(null)).to.equal(0); | ||
expect(Number.toInteger(undefined)).to.equal(0); | ||
expect(Number.toInteger(true)).to.equal(1); | ||
expect(Number.toInteger(false)).to.equal(0); | ||
expect(Number.toInteger({ | ||
valueOf: function() { return 4; } | ||
})).to.equal(4); | ||
expect(Number.toInteger({ | ||
valueOf: function() { return 4.3; } | ||
})).to.equal(4); | ||
expect(Number.toInteger({ | ||
valueOf: function() { return '4'; } | ||
})).to.equal(4); | ||
expect(Number.toInteger({ | ||
valueOf: function() { return {};} | ||
})).to.equal(0); | ||
expect(Number.toInteger()).to.equal(0); | ||
}); | ||
@@ -84,0 +167,0 @@ }); |
@@ -47,3 +47,3 @@ describe('Object', function() { | ||
}); | ||
describe('Object.getPropertyDescriptor()', function() { | ||
@@ -50,0 +50,0 @@ it('should produce an array of properties including inherited ones', |
@@ -11,5 +11,2 @@ describe('String', function() { | ||
expect('test'.startsWith('te')).to.be.ok; | ||
}); | ||
it('should be falsy on incorrect results', function() { | ||
expect('test'.startsWith('st')).to.not.be.ok; | ||
@@ -19,2 +16,51 @@ expect(''.startsWith('/')).to.not.be.ok; | ||
expect('##'.startsWith('///')).to.not.be.ok; | ||
expect('abc'.startsWith('abc')).to.be.ok; | ||
expect('abcd'.startsWith('abc')).to.be.ok; | ||
expect('abc'.startsWith('a')).to.be.ok; | ||
expect('abc'.startsWith('abcd')).to.not.be.ok; | ||
expect('abc'.startsWith('bcde')).to.not.be.ok; | ||
expect('abc'.startsWith('b')).to.not.be.ok; | ||
expect('abc'.startsWith('abc', 0)).to.be.ok; | ||
expect('abc'.startsWith('bc', 0)).to.not.be.ok; | ||
expect('abc'.startsWith('bc', 1)).to.be.ok; | ||
expect('abc'.startsWith('c', 1)).to.not.be.ok; | ||
expect('abc'.startsWith('abc', 1)).to.not.be.ok; | ||
expect('abc'.startsWith('c', 2)).to.be.ok; | ||
expect('abc'.startsWith('d', 2)).to.not.be.ok; | ||
expect('abc'.startsWith('dcd', 2)).to.not.be.ok; | ||
expect('abc'.startsWith('a', 42)).to.not.be.ok; | ||
expect('abc'.startsWith('a', Infinity)).to.not.be.ok; | ||
expect('abc'.startsWith('a', NaN)).to.be.ok; | ||
expect('abc'.startsWith('b', NaN)).to.not.be.ok; | ||
expect('abc'.startsWith('ab', -43)).to.be.ok; | ||
expect('abc'.startsWith('ab', -Infinity)).to.be.ok; | ||
expect('abc'.startsWith('bc', -42)).to.not.be.ok; | ||
expect('abc'.startsWith('bc', -Infinity)).to.not.be.ok; | ||
var myobj = { | ||
toString: function() {return 'abc';}, | ||
startsWith: String.prototype.startsWith | ||
}; | ||
expect(myobj.startsWith('abc')).to.be.ok; | ||
expect(myobj.startsWith('bc')).to.not.be.ok; | ||
var gotStr = false, gotPos = false; | ||
myobj = { | ||
toString: function() { | ||
expect(gotPos).to.not.be.ok; | ||
gotStr = true; | ||
return 'xyz'; | ||
}, | ||
startsWith: String.prototype.startsWith | ||
}; | ||
var idx = { | ||
valueOf: function() { | ||
expect(gotStr).to.be.ok; | ||
gotPos = true; | ||
return 42; | ||
} | ||
}; | ||
myobj.startsWith('elephant', idx); | ||
expect(gotPos).to.be.ok; | ||
}); | ||
@@ -26,5 +72,2 @@ }); | ||
expect('test'.endsWith('st')).to.be.ok; | ||
}) | ||
it('should be falsy on incorrect results', function() { | ||
expect('test'.endsWith('te')).to.not.be.ok; | ||
@@ -34,2 +77,51 @@ expect(''.endsWith('/')).to.not.be.ok; | ||
expect('##'.endsWith('///')).to.not.be.ok; | ||
expect('abc'.endsWith('abc')).to.be.ok; | ||
expect('abcd'.endsWith('bcd')).to.be.ok; | ||
expect('abc'.endsWith('c')).to.be.ok; | ||
expect('abc'.endsWith('abcd')).to.not.be.ok; | ||
expect('abc'.endsWith('bbc')).to.not.be.ok; | ||
expect('abc'.endsWith('b')).to.not.be.ok; | ||
expect('abc'.endsWith('abc', 3)).to.be.ok; | ||
expect('abc'.endsWith('bc', 3)).to.be.ok; | ||
expect('abc'.endsWith('a', 3)).to.not.be.ok; | ||
expect('abc'.endsWith('bc', 3)).to.be.ok; | ||
expect('abc'.endsWith('a', 1)).to.be.ok; | ||
expect('abc'.endsWith('abc', 1)).to.not.be.ok; | ||
expect('abc'.endsWith('b', 2)).to.be.ok; | ||
expect('abc'.endsWith('d', 2)).to.not.be.ok; | ||
expect('abc'.endsWith('dcd', 2)).to.not.be.ok; | ||
expect('abc'.endsWith('a', 42)).to.not.be.ok; | ||
expect('abc'.endsWith('bc', Infinity)).to.be.ok; | ||
expect('abc'.endsWith('a', Infinity)).to.not.be.ok; | ||
expect('abc'.endsWith('bc', undefined)).to.be.ok; | ||
expect('abc'.endsWith('bc', -43)).to.not.be.ok; | ||
expect('abc'.endsWith('bc', -Infinity)).to.not.be.ok; | ||
expect('abc'.endsWith('bc', NaN)).to.not.be.ok; | ||
var myobj = { | ||
toString: function() {return 'abc'}, | ||
endsWith: String.prototype.endsWith | ||
}; | ||
expect(myobj.endsWith('abc')).to.be.ok; | ||
expect(myobj.endsWith('ab')).to.not.be.ok; | ||
var gotStr = false, gotPos = false; | ||
myobj = { | ||
toString: function() { | ||
expect(gotPos).to.not.be.ok; | ||
gotStr = true; | ||
return 'xyz'; | ||
}, | ||
endsWith : String.prototype.endsWith | ||
}; | ||
var idx = { | ||
valueOf: function () { | ||
expect(gotStr).to.be.ok; | ||
gotPos = true; | ||
return 42; | ||
} | ||
}; | ||
myobj.endsWith('elephant', idx); | ||
expect(gotPos).to.be.ok; | ||
}); | ||
@@ -41,2 +133,58 @@ }); | ||
expect('test'.contains('es')).to.be.ok; | ||
expect('abc'.contains('a')).to.be.ok; | ||
expect('abc'.contains('b')).to.be.ok; | ||
expect('abc'.contains('abc')).to.be.ok; | ||
expect('abc'.contains('bc')).to.be.ok; | ||
expect('abc'.contains('d')).to.not.be.ok; | ||
expect('abc'.contains('abcd')).to.not.be.ok; | ||
expect('abc'.contains('ac')).to.not.be.ok; | ||
expect('abc'.contains('abc', 0)).to.be.ok; | ||
expect('abc'.contains('bc', 0)).to.be.ok; | ||
expect('abc'.contains('de', 0)).to.not.be.ok; | ||
expect('abc'.contains('bc', 1)).to.be.ok; | ||
expect('abc'.contains('c', 1)).to.be.ok; | ||
expect('abc'.contains('a', 1)).to.not.be.ok; | ||
expect('abc'.contains('abc', 1)).to.not.be.ok; | ||
expect('abc'.contains('c', 2)).to.be.ok; | ||
expect('abc'.contains('d', 2)).to.not.be.ok; | ||
expect('abc'.contains('dcd', 2)).to.not.be.ok; | ||
expect('abc'.contains('a', 42)).to.not.be.ok; | ||
expect('abc'.contains('a', Infinity)).to.not.be.ok; | ||
expect('abc'.contains('ab', -43)).to.be.ok; | ||
expect('abc'.contains('cd', -42)).to.not.be.ok; | ||
expect('abc'.contains('ab', -Infinity)).to.be.ok; | ||
expect('abc'.contains('cd', -Infinity)).to.not.be.ok; | ||
expect('abc'.contains('ab', NaN)).to.be.ok; | ||
expect('abc'.contains('cd', NaN)).to.not.be.ok; | ||
var myobj = { | ||
toString: function() {return 'abc';}, | ||
contains: String.prototype.contains | ||
}; | ||
expect(myobj.contains('abc')).to.be.ok; | ||
expect(myobj.contains('cd')).to.not.be.ok; | ||
var gotStr = false, gotPos = false; | ||
myobj = { | ||
toString: function() { | ||
expect(gotPos).to.not.be.ok; | ||
gotStr = true; | ||
return 'xyz'; | ||
}, | ||
contains: String.prototype.contains | ||
}; | ||
var idx = { | ||
valueOf: function() { | ||
expect(gotStr).to.be.ok; | ||
gotPos = true; | ||
return 42; | ||
} | ||
}; | ||
myobj.contains('elephant', idx); | ||
expect(gotPos).to.be.ok; | ||
}); | ||
@@ -43,0 +191,0 @@ |
Sorry, the diff of this file is not supported yet
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
45898
1150
1