ES2017 spec-compliant Object.values shim for cross-environment compatibility.
npx @tessl/cli install tessl/npm-object--values@1.2.0Object.values is an ES2017 spec-compliant shim for the Object.values method that works across all JavaScript environments. It provides a polyfill/shim that extracts enumerable property values from objects into an array, following the ECMAScript specification precisely while maintaining compatibility with legacy environments (ES3+).
npm install object.valuesvar values = require('object.values');var values = require('object.values');
var obj = { a: 1, b: 2, c: 3 };
var result = values(obj); // [1, 2, 3]
// Auto-shim for global usage
require('object.values/auto');
var result2 = Object.values(obj); // [1, 2, 3]Object.values follows the es-shim API pattern with multiple entry points:
Extract enumerable property values from objects in the same order as for...in iteration.
/**
* Extract enumerable property values from an object
* @param {any} O - Object to extract values from
* @returns {Array} Array of enumerable property values
* @throws {TypeError} If O cannot be converted to object
*/
function values(O);Usage Examples:
var values = require('object.values');
// Basic object
values({ a: 1, b: 2, c: 3 }); // [1, 2, 3]
// Mixed property types
values({ x: 'hello', y: 42, z: true }); // ['hello', 42, true]
// Array (returns array values, not indices)
values([10, 20, 30]); // [10, 20, 30]
// String (returns array of characters)
values('abc'); // ['a', 'b', 'c']
// Empty object
values({}); // []
// With symbol properties (symbols are ignored)
var obj = { a: 1, b: 2 };
if (typeof Symbol === 'function') {
var sym = Symbol('test');
obj[sym] = 'ignored';
}
values(obj); // [1, 2] - symbol properties are omitted
// Duplicate values are preserved
values({ a: 1, b: 1, c: 2 }); // [1, 1, 2]
// Property order follows for...in iteration order
var orderedObj = { b: 2, a: 1 };
orderedObj[0] = 'first';
orderedObj.c = 3;
values(orderedObj); // ['first', 2, 1, 3] - maintains property orderGet the appropriate Object.values implementation (native or polyfill).
/**
* Get the best available Object.values implementation
* @returns {Function} Native Object.values if spec-compliant, otherwise polyfill
*/
function getPolyfill();Usage:
var getPolyfill = require('object.values/polyfill');
var objectValues = getPolyfill();
// Use the returned function
objectValues({ a: 1, b: 2 }); // [1, 2]Install Object.values on the global Object if missing or non-compliant.
/**
* Install Object.values on global Object if needed
* @returns {Function} The installed polyfill function
*/
function shimValues();Usage:
var shimValues = require('object.values/shim');
var polyfill = shimValues();
// Object.values is now available globally
Object.values({ a: 1, b: 2 }); // [1, 2]Direct access to the core Object.values implementation.
/**
* Core Object.values implementation (bypasses native detection)
* @param {any} O - Object to extract values from
* @returns {Array} Array of enumerable property values
* @throws {TypeError} If O cannot be converted to object
*/
function implementation(O);Usage:
var implementation = require('object.values/implementation');
implementation({ a: 1, b: 2 }); // [1, 2]Automatically installs the shim when the module is required.
// Simply requiring this module installs the shim
require('object.values/auto');
// Object.values is now available globally
Object.values({ a: 1, b: 2 }); // [1, 2]The main export function includes additional properties for flexible usage:
// Main export has these attached properties:
values.getPolyfill; // Function reference: returns appropriate implementation
values.implementation; // Function reference: direct access to core algorithm
values.shim; // Function reference: installs global shimUsage:
var values = require('object.values');
// Use attached properties
var polyfill = values.getPolyfill();
var result1 = values.implementation({ a: 1 });
values.shim(); // Install globallyobject.values - Main function with attached properties (most common)object.values/polyfill - Get best available implementationobject.values/shim - Install global shim functionobject.values/implementation - Direct core implementationobject.values/auto - Automatic global shimmingfor...in iteration// These will throw TypeError:
values(null); // TypeError
values(undefined); // TypeError
// These work (primitives are converted to objects):
values(42); // [] (Number object has no enumerable properties)
values('abc'); // ['a', 'b', 'c']
values(true); // [] (Boolean object has no enumerable properties)