Back
extracted
object-keys
v1.1.1
MIT

objectKeys

A source-faithful extracted bundle of object-keys and its local helpers. Useful when you want the classic Object.keys shim behavior locally without adding another dependency.

Why copy this?

This page ships an extracted object-keys bundle with its local helpers inlined. The value is to keep the old shim behavior local and inspectable without another npm dependency.

Native alternative: Object.keys exists in modern runtimes, but some legacy or compatibility-heavy codebases still rely on the shim contract and its edge-case handling.

Note: This snippet is extracted rather than copied as-is because the published package entry depends on local helper files.

This copy is your responsibility once you adopt it. It does not automatically receive upstream bug fixes or security updates.

Snippet
Copy-first distribution
Normalized
ESM / TS / normalized
Runtime: node, bun
/**
 * Derived from [email protected]
 * Rule-based normalized variant generated by this repository.
 * Preserve the upstream license and attribution notices when copying this file.
 */
/**
 * Derived from [email protected]
 * Rule-based normalized variant generated by this repository.
 * See THIRD_PARTY_NOTICES.md for upstream license and attribution details.
 */
"use strict";
var slice = Array.prototype.slice;
var toStr = Object.prototype.toString;

var isArgs = function isArguments(value) {
  var str = toStr.call(value);
  var isArgsValue = str === "[object Arguments]";
  if (!isArgsValue) {
    isArgsValue =
      str !== "[object Array]" &&
      value !== null &&
      typeof value === "object" &&
      typeof value.length === "number" &&
      value.length >= 0 &&
      toStr.call(value.callee) === "[object Function]";
  }
  return isArgsValue;
};

var keysShim;
if (!Object.keys) {
  var has = Object.prototype.hasOwnProperty;
  var isEnumerable = Object.prototype.propertyIsEnumerable;
  var hasDontEnumBug = !isEnumerable.call({ toString: null }, "toString");
  var hasProtoEnumBug = isEnumerable.call(function () {}, "prototype");
  var dontEnums = [
    "toString",
    "toLocaleString",
    "valueOf",
    "hasOwnProperty",
    "isPrototypeOf",
    "propertyIsEnumerable",
    "constructor",
  ];
  var equalsConstructorPrototype = function (o) {
    var ctor = o.constructor;
    return ctor && ctor.prototype === o;
  };
  var excludedKeys = {
    $applicationCache: true,
    $console: true,
    $external: true,
    $frame: true,
    $frameElement: true,
    $frames: true,
    $innerHeight: true,
    $innerWidth: true,
    $onmozfullscreenchange: true,
    $onmozfullscreenerror: true,
    $outerHeight: true,
    $outerWidth: true,
    $pageXOffset: true,
    $pageYOffset: true,
    $parent: true,
    $scrollLeft: true,
    $scrollTop: true,
    $scrollX: true,
    $scrollY: true,
    $self: true,
    $webkitIndexedDB: true,
    $webkitStorageInfo: true,
    $window: true,
  };
  var hasAutomationEqualityBug = (function () {
    if (typeof window === "undefined") {
      return false;
    }
    for (var k in window) {
      try {
        if (
          !excludedKeys["$" + k] &&
          has.call(window, k) &&
          window[k] !== null &&
          typeof window[k] === "object"
        ) {
          try {
            equalsConstructorPrototype(window[k]);
          } catch (e) {
            return true;
          }
        }
      } catch (e) {
        return true;
      }
    }
    return false;
  })();
  var equalsConstructorPrototypeIfNotBuggy = function (o) {
    if (typeof window === "undefined" || !hasAutomationEqualityBug) {
      return equalsConstructorPrototype(o);
    }
    try {
      return equalsConstructorPrototype(o);
    } catch (e) {
      return false;
    }
  };

  keysShim = function keys(object) {
    var isObject = object !== null && typeof object === "object";
    var isFunction = toStr.call(object) === "[object Function]";
    var isArguments = isArgs(object);
    var isString = isObject && toStr.call(object) === "[object String]";
    var theKeys = [];

    if (!isObject && !isFunction && !isArguments) {
      throw new TypeError("Object.keys called on a non-object");
    }

    var skipProto = hasProtoEnumBug && isFunction;
    if (isString && object.length > 0 && !has.call(object, 0)) {
      for (var i = 0; i < object.length; ++i) {
        theKeys.push(String(i));
      }
    }

    if (isArguments && object.length > 0) {
      for (var j = 0; j < object.length; ++j) {
        theKeys.push(String(j));
      }
    } else {
      for (var name in object) {
        if (!(skipProto && name === "prototype") && has.call(object, name)) {
          theKeys.push(String(name));
        }
      }
    }

    if (hasDontEnumBug) {
      var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);

      for (var m = 0; m < dontEnums.length; ++m) {
        if (
          !(skipConstructor && dontEnums[m] === "constructor") &&
          has.call(object, dontEnums[m])
        ) {
          theKeys.push(dontEnums[m]);
        }
      }
    }
    return theKeys;
  };
}

var origKeys = Object.keys;
keysShim = origKeys
  ? function keys(o) {
      return origKeys(o);
    }
  : keysShim;

var originalKeys = Object.keys;

keysShim.shim = function shimObjectKeys() {
  if (Object.keys) {
    var keysWorksWithArguments = (function () {
      var args = Object.keys(arguments);
      return args && args.length === arguments.length;
    })(1, 2);
    if (!keysWorksWithArguments) {
      Object.keys = function keys(object) {
        if (isArgs(object)) {
          return originalKeys(slice.call(object));
        }
        return originalKeys(object);
      };
    }
  } else {
    Object.keys = keysShim;
  }
  return Object.keys || keysShim;
};

export default keysShim;
Variant note: Rule-based normalization after extraction. The extraction defines the raw bundle; normalization only changes the packaging shape.
Transforms: module.exports-to-export-default, js-extension-to-ts-extension
Validation: This normalized variant is intended to stay oxlint and oxfmt clean in this repo.
Raw
CJS / JS / raw
Runtime: node, bun
'use strict';

var slice = Array.prototype.slice;
var toStr = Object.prototype.toString;

var isArgs = function isArguments(value) {
  var str = toStr.call(value);
  var isArgsValue = str === '[object Arguments]';
  if (!isArgsValue) {
    isArgsValue = str !== '[object Array]' &&
      value !== null &&
      typeof value === 'object' &&
      typeof value.length === 'number' &&
      value.length >= 0 &&
      toStr.call(value.callee) === '[object Function]';
  }
  return isArgsValue;
};

var keysShim;
if (!Object.keys) {
  var has = Object.prototype.hasOwnProperty;
  var isEnumerable = Object.prototype.propertyIsEnumerable;
  var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString');
  var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype');
  var dontEnums = [
    'toString',
    'toLocaleString',
    'valueOf',
    'hasOwnProperty',
    'isPrototypeOf',
    'propertyIsEnumerable',
    'constructor'
  ];
  var equalsConstructorPrototype = function (o) {
    var ctor = o.constructor;
    return ctor && ctor.prototype === o;
  };
  var excludedKeys = {
    $applicationCache: true,
    $console: true,
    $external: true,
    $frame: true,
    $frameElement: true,
    $frames: true,
    $innerHeight: true,
    $innerWidth: true,
    $onmozfullscreenchange: true,
    $onmozfullscreenerror: true,
    $outerHeight: true,
    $outerWidth: true,
    $pageXOffset: true,
    $pageYOffset: true,
    $parent: true,
    $scrollLeft: true,
    $scrollTop: true,
    $scrollX: true,
    $scrollY: true,
    $self: true,
    $webkitIndexedDB: true,
    $webkitStorageInfo: true,
    $window: true
  };
  var hasAutomationEqualityBug = (function () {
    if (typeof window === 'undefined') { return false; }
    for (var k in window) {
      try {
        if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
          try {
            equalsConstructorPrototype(window[k]);
          } catch (e) {
            return true;
          }
        }
      } catch (e) {
        return true;
      }
    }
    return false;
  }());
  var equalsConstructorPrototypeIfNotBuggy = function (o) {
    if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
      return equalsConstructorPrototype(o);
    }
    try {
      return equalsConstructorPrototype(o);
    } catch (e) {
      return false;
    }
  };

  keysShim = function keys(object) {
    var isObject = object !== null && typeof object === 'object';
    var isFunction = toStr.call(object) === '[object Function]';
    var isArguments = isArgs(object);
    var isString = isObject && toStr.call(object) === '[object String]';
    var theKeys = [];

    if (!isObject && !isFunction && !isArguments) {
      throw new TypeError('Object.keys called on a non-object');
    }

    var skipProto = hasProtoEnumBug && isFunction;
    if (isString && object.length > 0 && !has.call(object, 0)) {
      for (var i = 0; i < object.length; ++i) {
        theKeys.push(String(i));
      }
    }

    if (isArguments && object.length > 0) {
      for (var j = 0; j < object.length; ++j) {
        theKeys.push(String(j));
      }
    } else {
      for (var name in object) {
        if (!(skipProto && name === 'prototype') && has.call(object, name)) {
          theKeys.push(String(name));
        }
      }
    }

    if (hasDontEnumBug) {
      var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);

      for (var m = 0; m < dontEnums.length; ++m) {
        if (!(skipConstructor && dontEnums[m] === 'constructor') && has.call(object, dontEnums[m])) {
          theKeys.push(dontEnums[m]);
        }
      }
    }
    return theKeys;
  };
}

var origKeys = Object.keys;
keysShim = origKeys ? function keys(o) { return origKeys(o); } : keysShim;

var originalKeys = Object.keys;

keysShim.shim = function shimObjectKeys() {
  if (Object.keys) {
    var keysWorksWithArguments = (function () {
      var args = Object.keys(arguments);
      return args && args.length === arguments.length;
    }(1, 2));
    if (!keysWorksWithArguments) {
      Object.keys = function keys(object) {
        if (isArgs(object)) {
          return originalKeys(slice.call(object));
        }
        return originalKeys(object);
      };
    }
  } else {
    Object.keys = keysShim;
  }
  return Object.keys || keysShim;
};

module.exports = keysShim;
Variant note: Source-faithful extracted bundle from the published package, with local helper modules inlined and module boundaries removed.