or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-object--values

ES2017 spec-compliant Object.values shim for cross-environment compatibility.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/object.values@1.2.x

To install, run

npx @tessl/cli install tessl/npm-object--values@1.2.0

index.mddocs/

Object.values

Object.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+).

Package Information

  • Package Name: object.values
  • Package Type: npm
  • Language: JavaScript (ES3+)
  • Installation: npm install object.values

Core Imports

var values = require('object.values');

Basic Usage

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]

Architecture

Object.values follows the es-shim API pattern with multiple entry points:

  • Main API: Direct function usage for extracting values
  • Polyfill Detection: Feature detection to use native implementation when available
  • Global Shimming: Optional installation of Object.values on the global Object
  • Auto-shimming: Immediate global installation for convenience
  • Implementation Access: Direct access to the core algorithm

Capabilities

Main Function

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 order

Polyfill Function

Get 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]

Shim Installation

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]

Implementation Access

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]

Auto-shimming

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]

Properties on Main Export

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 shim

Usage:

var values = require('object.values');

// Use attached properties
var polyfill = values.getPolyfill();
var result1 = values.implementation({ a: 1 });
values.shim(); // Install globally

Entry Points Summary

  • object.values - Main function with attached properties (most common)
  • object.values/polyfill - Get best available implementation
  • object.values/shim - Install global shim function
  • object.values/implementation - Direct core implementation
  • object.values/auto - Automatic global shimming

Behavior Specifications

Property Selection

  • Enumerable Only: Only enumerable properties are included (non-enumerable properties are omitted)
  • Own Properties: Inherited properties are ignored
  • Symbol Properties: Symbol properties are omitted
  • Order: Values appear in same order as for...in iteration
  • Dynamic Changes: Properties deleted or made non-enumerable during iteration are handled per ES specification

Type Coercion

  • Objects: Processed directly
  • Primitives: Converted to objects first (strings become character arrays)
  • null/undefined: Throws TypeError (following ES spec)

Error Handling

// 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)