web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.9 KiB

  1. # array-includes <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
  2. [![Build Status][travis-svg]][travis-url]
  3. [![dependency status][deps-svg]][deps-url]
  4. [![dev dependency status][dev-deps-svg]][dev-deps-url]
  5. [![License][license-image]][license-url]
  6. [![Downloads][downloads-image]][downloads-url]
  7. [![npm badge][npm-badge-png]][package-url]
  8. An ES7/ES2016 spec-compliant `Array.prototype.includes` shim/polyfill/replacement that works as far down as ES3.
  9. 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 proposed [spec](http://www.ecma-international.org/ecma-262/6.0/).
  10. Because `Array.prototype.includes` depends on a receiver (the `this` value), the main export takes the array to operate on as the first argument.
  11. ## Getting started
  12. ```sh
  13. npm install --save array-includes
  14. ```
  15. ## Usage
  16. Basic usage: **includes(array, value[, fromIndex=0])**
  17. ```js
  18. var includes = require('array-includes');
  19. var assert = require('assert');
  20. var arr = [ 'one', 'two' ];
  21. includes(arr, 'one'); // true
  22. includes(arr, 'three'); // false
  23. includes(arr, 'one', 1); // false
  24. ```
  25. ## Example
  26. ```js
  27. var arr = [
  28. 1,
  29. 'foo',
  30. NaN,
  31. -0
  32. ];
  33. assert.equal(arr.indexOf(0) > -1, true);
  34. assert.equal(arr.indexOf(-0) > -1, true);
  35. assert.equal(includes(arr, 0), true);
  36. assert.equal(includes(arr, -0), true);
  37. assert.equal(arr.indexOf(NaN) > -1, false);
  38. assert.equal(includes(arr, NaN), true);
  39. assert.equal(includes(arr, 'foo', 0), true);
  40. assert.equal(includes(arr, 'foo', 1), true);
  41. assert.equal(includes(arr, 'foo', 2), false);
  42. ```
  43. ```js
  44. /* when Array#includes is not present */
  45. delete Array.prototype.includes;
  46. var shimmedIncludes = includes.shim();
  47. assert.equal(shimmedIncludes, includes.getPolyfill());
  48. assert.equal(arr.includes('foo', 1), includes(arr, 'foo', 1));
  49. ```
  50. ```js
  51. /* when Array#includes is present */
  52. var shimmedIncludes = includes.shim();
  53. assert.equal(shimmedIncludes, Array.prototype.includes);
  54. assert.equal(arr.includes(1, 'foo'), includes(arr, 1, 'foo'));
  55. ```
  56. ## Tests
  57. Simply clone the repo, `npm install`, and run `npm test`
  58. [package-url]: https://npmjs.org/package/array-includes
  59. [npm-version-svg]: http://versionbadg.es/es-shims/array-includes.svg
  60. [travis-svg]: https://travis-ci.org/es-shims/array-includes.svg
  61. [travis-url]: https://travis-ci.org/es-shims/array-includes
  62. [deps-svg]: https://david-dm.org/es-shims/array-includes.svg
  63. [deps-url]: https://david-dm.org/es-shims/array-includes
  64. [dev-deps-svg]: https://david-dm.org/es-shims/array-includes/dev-status.svg
  65. [dev-deps-url]: https://david-dm.org/es-shims/array-includes#info=devDependencies
  66. [npm-badge-png]: https://nodei.co/npm/array-includes.png?downloads=true&stars=true
  67. [license-image]: http://img.shields.io/npm/l/array-includes.svg
  68. [license-url]: LICENSE
  69. [downloads-image]: http://img.shields.io/npm/dm/array-includes.svg
  70. [downloads-url]: http://npm-stat.com/charts.html?package=array-includes