Skip to content

Commit

Permalink
use call-bind
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Jul 12, 2024
1 parent 2d269da commit f96aa91
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
14 changes: 8 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
var whichTypedArray = require('which-typed-array');
var taSlice = require('typedarray.prototype.slice');
var gopd = require('gopd');
var callBound = require('call-bind/callBound');

// TODO: use call-bind, is-date, is-regex, is-string, is-boolean-object, is-number-object
function toS(obj) { return Object.prototype.toString.call(obj); }
var toS = callBound('Object.prototype.toString');

// TODO: is-date, is-regex, is-string, is-boolean-object, is-number-object
function isDate(obj) { return toS(obj) === '[object Date]'; }
function isRegExp(obj) { return toS(obj) === '[object RegExp]'; }
function isError(obj) { return toS(obj) === '[object Error]'; }
Expand All @@ -15,7 +17,7 @@ function isString(obj) { return toS(obj) === '[object String]'; }

// TODO: use isarray
var isArray = Array.isArray || function isArray(xs) {
return Object.prototype.toString.call(xs) === '[object Array]';
return toS(xs) === '[object Array]';
};

// TODO: use for-each?
Expand All @@ -34,8 +36,8 @@ var objectKeys = Object.keys || function keys(obj) {
return res;
};

var propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
var getOwnPropertySymbols = Object.getOwnPropertySymbols; // eslint-disable-line id-length
var propertyIsEnumerable = callBound('Object.prototype.propertyIsEnumerable');
var getOwnPropertySymbols = callBound('Object.getOwnPropertySymbols'); // eslint-disable-line id-length

// TODO: use reflect.ownkeys and filter out non-enumerables
function ownEnumerableKeys(obj) {
Expand All @@ -45,7 +47,7 @@ function ownEnumerableKeys(obj) {
if (getOwnPropertySymbols) {
var symbols = getOwnPropertySymbols(obj);
for (var i = 0; i < symbols.length; i++) {
if (propertyIsEnumerable.call(obj, symbols[i])) {
if (propertyIsEnumerable(obj, symbols[i])) {
res.push(symbols[i]);
}
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@ljharb/eslint-config": "^21.1.0",
"aud": "^2.0.4",
"auto-changelog": "^2.4.0",
"call-bind": "^1.0.7",
"es-value-fixtures": "^1.4.2",
"eslint": "=8.8.0",
"in-publish": "^2.0.1",
Expand Down

0 comments on commit f96aa91

Please sign in to comment.