Package detail

@es-shims/api

es-shims12.3kMIT3.0.2

Loosely test a package's compliance with the es-shim API

API, shim, polyfill, ponyfill

readme

es-shim API Version Badge

github actions coverage License Downloads

npm badge

API Contract

For any given “es-shim API v3”-compliant package foo, the following invariants must hold:

  • This package will run in an environment supporting the oldest JS version in which the spec’s semantics are achievable - ES3, ES5, and/or ES6. The package should indicate its minimum level of required environment support in its README.
  • The package must attempt to support node/io.js, all versions of all ES3-compliant browsers or later, Web Workers, and node-webkit. Other environments are a plus, but not expected.
  • require('foo') is a spec-compliant JS or native function. However, if the function’s behavior depends on a receiver (a “this” value), then the first argument to this function will be used as that receiver. The package should indicate if this is the case in its README.
    • In the case of static methods like Promise.all that depend on their receiver without a fallback, the index must ensure that receiverless invocation acts as if the static method was called on its original object, but must also allow .call/.bind/.apply to alter the receiver when relevant.
  • require('foo/implementation') is a spec-compliant JS function, that will depend on a receiver (a “this” value) as the spec requires.
  • require('foo/polyfill') is a function that when invoked, will return the most compliant and performant function that it can - if a native version is available, and does not violate the spec, then the native function will be returned - otherwise, either the implementation, or a custom, wrapped version of the native function, will be returned. This is also the result that will be used as the default export.
  • require('foo/shim') is a function that when invoked, will call getPolyfill, and if the polyfill doesn’t match the built-in value, will install it into the global environment.
  • require('foo/auto') will automatically invoke the shim method.
  • The only place the package may modify the environment is within its shim method.
  • Naturally, npm test must run the package’s tests.
  • In every way possible, the package must attempt to make itself robust against the environment being modified after it is required.
    • For example, require('foo'); delete Function.prototype.call; must not alter the behavior of foo.
    • The most useful technique for this is shown in this example: var callBound = require('call-bound'); var slice = callBound('Array.prototype.slice'); slice([1], 1); — this technique works in ES3 environments, and will ensure that modifying Array.prototype or Function.prototype will not interfere with the package.

Multi-shim Packages

If your package contains multiple shims, you can pass --multi to apply these invariants:

  • The package's main export must be an array of directory names, with no additional properties.
  • The entry points and respective invariants listed above apply to the subdirectories listed in the main export
  • The root must contain shim and auto entrypoints that match the same invariants described above. The shim entry point must invoke the shim entry point in each of the subdirectories listed in the main export
  • The root must NOT contain an implementation entry point.

Recommended dependencies

  • Please use the es-abstract package to ensure spec-compliant behavior via the spec’s internal abstract operations.
  • Please use the define-properties package to trivially define non-enumerable properties, where supported.
  • Please use the call-bind package to cache references to all builtin methods, to be robust against later modification of the environment.

How to denote compliance

Prominently in the package’s README, please include the following markdown:

This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment and complies with the [spec](https://www.ecma-international.org/ecma-262/6.0/).

Please modify “ES3” as needed to the level of support, and please update the spec link so it points directly to the most relevant section of the spec it complies with.

Binary

Very simple and shallow tests that a package follows the es-shim API.

Pass --bound to indicate that the function the package is implementing depends on having a receiver (a “this” value). In particular, this applies to something that is a prototype method, or a static method that depends on its receiver.

Example

es-shim-api object-assign
es-shim-api array-includes --bound

Tests

Simply clone the repo, npm install, and run npm test

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v3.0.2 - 2024-12-11

Commits

  • [Fix] avoid a crash when the module is not an object 51037e8
  • [Dev Deps] update @arethetypeswrong/cli, @ljharb/tsconfig, @types/node, @types/tape 4b5810a
  • [Deps] update object-inspect 28f8f60
  • [readme] refer to extracted call-bound package 59ffc02

v3.0.1 - 2024-09-20

Commits

  • [Dev Deps] update @arethetypeswrong/cli, auto-changelog 5fcf97e
  • [Fix] multi: do not assume bound vs unbound 28bca87
  • [Deps] update tape 4a0c3cd

v3.0.0 - 2024-09-19

Commits

  • [Breaking] require node 20.17 84bb1ec
  • [Refactor] use pargs and ESM 21e483c
  • [New] add types 3caf579
  • [Docs] update shims list 531e6f1
  • [Breaking] condense some booleans into enum type arg d205d23
  • [Breaking] remove expando properties from the index 27975e1
  • [Deps] remove some unneeded packages 64bb6cd
  • [Deps] update semver abd2974
  • [Breaking] add exports f57bc0a

v2.5.1 - 2024-09-04

Commits

  • [Fix] ensure a bound index does not mutate the builtin 568ddaf
  • [Fix] ensure bound shim is actually bound 04ec735
  • [Deps] update object-inspect, tape eaf5581
  • [Tests] replace aud with npm audit bfc8156
  • [Dev Deps] update @ljharb/eslint-config 3ba4c80

v2.5.0 - 2024-03-24

Fixed

  • [meta] fix badges and URLs #27

Commits

  • [New] --multi: ensure all declared subpackages have proper exports 8bf6ae2
  • [New] automatically detect --multi mode 4e7f6d7
  • [Deps] update array-includes, array.prototype.flatmap, object-inspect, tape 2b75c3e
  • [Deps] update array-includes, tape 906b618
  • [Dev Deps] update aud, npmignore 1bfc395
  • [Dev Deps] update @ljharb/eslint-config, aud 4f6fced

v2.4.2 - 2023-05-15

Commits

  • [Fix] handle exports with an array RHS 32d8fa3

v2.4.1 - 2023-05-03

Commits

  • [Fix] in --multi, exports should not have polyfill or impl entrypoints a6f4a41

v2.4.0 - 2023-05-02

Commits

  • [New] add check for exports field f6f7920

v2.3.1 - 2023-02-17

Commits

  • [meta] add auto-changelog 7ba8adb
  • [Fix] allow multi to be non-functions, as long as they are defined 4cb4210

2.3.0 / 2023-02-04

  • [New] add --ignore-dirs option to be used with --multi
  • [Deps] update tape
  • [meta] use npmignore to autogenerate an npmignore file
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, `safe-publish-latest
  • [actions] update rebase action to use reusable workflow
  • [actions] reuse common workflows

2.2.3 / 2021-10-04

  • [Fix] multi: sort package list before comparing

2.2.2 / 2021-10-03

  • [Deps] remove unused deps

2.2.1 / 2021-09-02

  • [Fix] --multi: test subpackages’ auto endpoint
  • [Fix] --multi: skip coverage directory

2.2.0 / 2021-09-02

  • [New] add --multi, to support one package containing multiple shims
  • [readme] add github actions/codecov badges; update URLs
  • [readme] remove travis badge
  • [Docs] update shims list
  • [shims] Adds Array.isTemplateObject (#17)
  • [meta] remove unused Makefile and associated utilities
  • [meta] add funding field
  • [meta] do not publish github action workflow files
  • [meta] Quote keyword in npm search link, due to a bug in npmjs.com
  • [actions] update workflows
  • [actions] add "Allow Edits" workflow
  • [actions] switch Automatic Rebase workflow to pull_request_target event
  • [actions] add automatic rebasing / merge commit blocking
  • [Dev Deps] update eslint, @ljharb/eslint-config, make-arrow-function, make-generator-function; add safe-publish-latest
  • [Tests] migrate tests to Github Actions
  • [Tests] use npx aud instead of nsp or npm audit with hoops
  • [Tests] remove jscs

2.1.2 / 2017-12-30

  • [Fix] ensure the "auto" test works prior to node 0.12

2.1.1 / 2017-12-21

  • [Fix] fix new auto test

2.1.0 / 2017-12-21

  • [New] improve auto test

2.0.0 / 2017-12-20

  • [Breaking] add auto requirement (#16)
  • [Deps] update tape
  • [Dev Deps] update eslint, @ljharb/eslint-config, nsp

1.3.0 / 2017-07-26

  • [New] add --skip-shim-returns-polyfill
  • [Refactor] ensure --property test indicates how to skip it
  • [Refactor] skip all ---prefixed args.
  • [Refactor] consolidate argEquals implementations
  • [Dev Deps] update eslint, @ljharb/eslint-config, nsp, semver, jscs
  • [Tests] up to node v8.2, v7.10, v6.11, v4.8; improve matrix; newer npm breaks on older node
  • [Docs] Update shims list.

1.2.0 / 2016-03-29

  • [New] Add --property to skip check that implementation is a function
  • [Deps] update tape
  • [Dev Deps] update jscs, nsp, eslint, @ljharb/eslint-config
  • [Tests] up to node v5.9, v4.4

1.1.0 / 2016-02-06

  • [New] Require that the default export be getPolyfill() instead of implementation
  • [Fix] Handle the case where package.json's "main" entry point is not index.js
  • [Fix] Make sure existsSync works in node 0.6 and below
  • [Deps] update tape
  • [Dev Deps] update jscs, eslint, @ljharb/eslint-config, nsp, semver
  • [Tests] up to node v5.5
  • [Tests] fix npm upgrades for older nodes

1.0.0 / 2015-08-15

  • Initial release.