Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@es-shims/api

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@es-shims/api

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

  • 2.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
157
decreased by-55.65%
Maintainers
2
Weekly downloads
 
Created
Source

es-shim API Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

API Contract

For any given “es-shim API”-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.
  • require('foo').implementation or require('foo/implementation') is a spec-compliant JS function, that will depend on a receiver (a “this” value) as the spec requires.
  • require('foo').getPolyfill or 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 or 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 bind = require('function-bind'); var slice = bind.call(Function.call, Array.prototype.slice); slice([1], 1); — this technique works in ES3 environments, and will ensure that modifying Array.prototype will not interfere with the package.
  • Please use the es-abstract module to ensure spec-compliant behavior via the spec’s internal abstract operations.
  • Please use the define-properties module to trivially define non-enumerable properties, where supported.
  • Please use the function-bind module 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](http://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).

Example

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

Tests

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

Keywords

FAQs

Package last updated on 30 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc