-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from mathiasbynens/nr/es-shim-api
- Loading branch information
Showing
15 changed files
with
302 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
end_of_line = lf | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
version: ~> 1.0 | ||
language: node_js | ||
node_js: | ||
- "0.10" | ||
os: | ||
- linux | ||
import: | ||
- ljharb/travis-ci:node/all.yml | ||
- ljharb/travis-ci:node/pretest.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/*! https://mths.be/includes v2.0.0 by @mathias */ | ||
|
||
require('./shim')(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*! https://mths.be/includes v2.0.0 by @mathias */ | ||
|
||
'use strict'; | ||
|
||
var callBound = require('es-abstract/helpers/callBound') | ||
var RequireObjectCoercible = require('es-abstract/2019/RequireObjectCoercible'); | ||
var ToString = require('es-abstract/2019/ToString'); | ||
var ToInteger = require('es-abstract/2019/ToInteger'); | ||
var IsRegExp = require('es-abstract/2019/IsRegExp'); | ||
|
||
var min = Math.min; | ||
var max = Math.max; | ||
var indexOf = callBound('String.prototype.indexOf'); | ||
|
||
module.exports = function includes(searchString) { | ||
var O = RequireObjectCoercible(this); | ||
var S = ToString(O); | ||
if (IsRegExp(searchString)) { | ||
throw TypeError('Argument to String.prototype.includes cannot be a RegExp'); | ||
} | ||
var searchStr = String(searchString); | ||
var searchLength = searchStr.length; | ||
var position = arguments.length > 1 ? arguments[1] : undefined; | ||
var pos = ToInteger(position); | ||
var len = S.length; | ||
var start = min(max(pos, 0), len); | ||
// Avoid the `indexOf` call if no match is possible | ||
if (searchLength + start > len) { | ||
return false; | ||
} | ||
return indexOf(S, searchStr, pos) != -1; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/*! https://mths.be/includes v2.0.0 by @mathias */ | ||
|
||
'use strict'; | ||
|
||
var callBind = require('es-abstract/helpers/callBind'); | ||
var define = require('define-properties'); | ||
|
||
var implementation = require('./implementation'); | ||
var getPolyfill = require('./polyfill'); | ||
var shim = require('./shim'); | ||
|
||
var boundIncludes = callBind(getPolyfill()); | ||
|
||
define(boundIncludes, { | ||
getPolyfill: getPolyfill, | ||
implementation: implementation, | ||
shim: shim | ||
}); | ||
|
||
module.exports = boundIncludes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/*! https://mths.be/includes v2.0.0 by @mathias */ | ||
|
||
'use strict'; | ||
|
||
var implementation = require('./implementation'); | ||
|
||
module.exports = function getPolyfill() { | ||
return String.prototype.includes || implementation; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/*! https://mths.be/includes v2.0.0 by @mathias */ | ||
|
||
'use strict'; | ||
|
||
var define = require('define-properties'); | ||
|
||
var getPolyfill = require('./polyfill'); | ||
|
||
module.exports = function shimIncludes() { | ||
var polyfill = getPolyfill(); | ||
|
||
if (String.prototype.includes !== polyfill) { | ||
define(String.prototype, { includes: polyfill }); | ||
} | ||
|
||
return polyfill; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
var includes = require('../'); | ||
var test = require('tape'); | ||
|
||
var runTests = require('./tests'); | ||
|
||
test('as a function', function (t) { | ||
runTests(includes, t); | ||
|
||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
var includes = require('../'); | ||
includes.shim(); | ||
|
||
var test = require('tape'); | ||
var defineProperties = require('define-properties'); | ||
var bind = require('function-bind'); | ||
var isEnumerable = Object.prototype.propertyIsEnumerable; | ||
var functionsHaveNames = require('functions-have-names')(); | ||
|
||
var runTests = require('./tests'); | ||
|
||
test('shimmed', function (t) { | ||
t.equal(String.prototype.includes.length, 1, 'String#includes has a length of 1'); | ||
|
||
t.test('Function name', { skip: !functionsHaveNames }, function (st) { | ||
st.equal(String.prototype.includes.name, 'includes', 'String#includes has name "includes"'); | ||
st.end(); | ||
}); | ||
|
||
t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (st) { | ||
st.equal(false, isEnumerable.call(String.prototype, 'includes'), 'String#includes is not enumerable'); | ||
st.end(); | ||
}); | ||
|
||
runTests(bind.call(Function.call, String.prototype.includes), t); | ||
|
||
t.end(); | ||
}); |
Oops, something went wrong.