{"id":13657640,"url":"https://github.com/getify/ES-Feature-Tests","last_synced_at":"2025-04-24T01:32:37.634Z","repository":{"id":31505396,"uuid":"35069690","full_name":"getify/ES-Feature-Tests","owner":"getify","description":"Feature Tests for JavaScript","archived":true,"fork":false,"pushed_at":"2015-08-30T14:57:32.000Z","size":208,"stargazers_count":199,"open_issues_count":11,"forks_count":16,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-14T13:10:54.006Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/getify.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-05T01:13:14.000Z","updated_at":"2024-02-23T19:57:11.000Z","dependencies_parsed_at":"2022-08-24T15:52:03.100Z","dependency_job_id":null,"html_url":"https://github.com/getify/ES-Feature-Tests","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getify%2FES-Feature-Tests","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getify%2FES-Feature-Tests/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getify%2FES-Feature-Tests/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getify%2FES-Feature-Tests/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/getify","download_url":"https://codeload.github.com/getify/ES-Feature-Tests/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250544112,"owners_count":21448043,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T05:00:47.346Z","updated_at":"2025-04-24T01:32:37.350Z","avatar_url":"https://github.com/getify.png","language":"JavaScript","readme":"# ES Feature Tests\n\nFeature Tests for JavaScript. This is the library used by the [FeatureTests.io](https://featuretests.io) service.\n\n**If you're looking for the repository for the site itself, not this library, [go here instead](http://github.com/getify/featuretests.io).**\n\n## Why\n\nLoad the library, request feature test results for the current browser, use those results to determine what code to deliver for your application!\n\nIf all the JavaScript features/syntax your code uses are supported natively by the browser, why would you load up the ugly transpiled code? Why would you load **dozens of kb** of polyfills/shims if all (or most of) those APIs are already built-in?\n\nJust use the original authored ES6+ code in newest browsers! Only use transpiled code and polyfills/shims for browsers which are missing the features/syntax you need.\n\nDon't rely on stale caniuse data baked into build tools that matches a browser based on brittle UserAgent string parsing. **Feature Test!** That's the most reliable and sensible approach.\n\nFor much more detail about the *why* motivations and sanity checking the risks/concerns about scalability/reliability, see [ES6: Features By Testing](http://davidwalsh.name/es6-features-testing).\n\n## Documentation\n\nThe updated and detailed documentation for how this library works and what test results are available can be found on [FeatureTests.io/details](https://featuretests.io/details).\n\n## Hosting vs. Hosted\n\nHosting this package locally on your server is mostly useful if you want to use the feature tests in your Node/iojs programs (see \"Node/iojs\" below).\n\nYou *can* install this package locally and web host your own copy of the library files if you prefer. You'll need to modify the URLs (\"https://featuretests.io\") in several places to get them to load correctly. Hosting the files also means the test results won't be shareable with other sites, which puts more testing burden on users' machines.\n\nAnother concern that only applies if you're self-hosting and running your own tests is that all of the syntax-realted tests require using `new Function(..)` (or, ugh, `eval(..)`). If your site has a restrictive [CSP](https://developer.mozilla.org/en-US/docs/Web/Security/CSP), you will not be able to run those tests unless you relax it to allow `unsafe-eval`. By allowing the service to run the tests, that CSP policy is contained to the \"featuretests.io\" domain instead of polluting your site's domain.\n\nIt's probably a much better idea to use the \"https://featuretests.io\" service's hosted versions of the files for web usage.\n\n## Web\n\nUsing this library on the web:\n\n```html\n\u003cscript src=\"https://featuretests.io/rs.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\nwindow[\"Reflect.supports\"]( \"all\", function(results,timestamp){\n\tconsole.log( results );\n\t// {\n\t//    ..\n\t// }\n});\n\u003c/script\u003e\n```\n\n## Node/iojs\n\nUsing this library in Node/iojs:\n\n```\nnpm install es-feature-tests\n```\n\nThen:\n\n```js\nvar ReflectSupports = require(\"es-feature-tests\");\n\nReflectSupports( \"all\", function(results,timestamp){\n\tconsole.log( results );\n\t// {\n\t//    ..\n\t// }\n});\n```\n\n## Testify CLI\n\nThis package also includes a `testify` CLI tool, which scans files for ES6 features and produces the code for a JS function called `checkFeatureTests(..)`. For example:\n\n```js\nfunction checkFeatureTests(testResults){return testResults.letConst\u0026\u0026testResults.templateString}\n```\n\nAs shown, `checkFeatureTests(..)` receives the feature test results (as provided by this *es-feature-tests* library), and returns `true` or `false` indicating if the test results are sufficient or not. This test tells you if your ES6-authored files can be loaded directly into the environment in question, or if you need to load the transpiled version of your code.\n\nIn the preceding example, both the `letConst` test result and the `templateString` test result must pass for `checkFeatureTests(..)` to pass.\n\nBy letting `testify` scan your files, you won't need to manually maintain a list of checks for your code base. Just simply run `testify` during your build process, and include the code it produces (like shown above) into your initial bootstrapped code that will run the feature tests. Use the generated `checkFeatureTests(..)` with the *es-feature-tests* library like so:\n\n```js\nvar supports = window[\"Reflect.supports\"];\n\n// or in Node:\n// var supports = require(\"es-feature-tests\");\n\nsupports( \"all\", function(results){\n\tif (checkFeatureTests(results)) {\n\t\t// load ES6 code\n\t}\n\telse {\n\t\t// load transpiled code instead\n\t}\n});\n```\n\nThe `testify` CLI tool has the following options:\n\n```\nusage: testify [--file|--dir]=path [opt ...]\n\noptions:\n--help                    show this help\n\n--file=file               scan a single file\n--dir=directory           scan all files in a directory\n--exclude=pattern         exclude any included paths that match pattern (JS regex)\n-C, --input               scan file contents from STDIN\n\n--output=[simple|json|babel|traceur]\n                          control output format (see docs)\n                          (default: simple)\n--enable=test-name        force inclusion of a test by name\n--disable=test-name       force exclusion of a test by name\n\n-R, --recursive           directory scan is recursive\n                          (default: off)\n-M, --ignore-missing      ignore missing dependency files\n                          (default: off)\n-I, --ignore-invalid      ignore JS parsing issues\n                          (default: off)\n```\n\nSpecify file(s) to scan by using one or more `--file` and/or `--dir` flags, and/or import text contents via `STDIN` by specifying `--input (-C)`.\n\nIf you use `--dir`, that directory's contents will be examined (non-recursively), and all found JS files will be scanned. Use `--recursive (-R)` to recursively examine sub-directories. To exclude any files/paths from this processing, use one or more `--exclude` flags, specifying a JS-style regular expression to match for exclusion (note: to avoid shell escaping issues, surround your regex in ' ' quotes).\n\nThe default (`--output=simple`) output of the `testify` CLI tool is the code for the `checkFeatureTests(..)` function, as described above. If you'd prefer to receive a JSON string holding the array of tests needed by name, specify `--output=json`. If you want to produce a [Babel](https://babeljs.io) config with tests needed mapped to the [`whitelist` option](https://babeljs.io/docs/usage/options/), use `--output=babel`. To produce the configuration for Traceur, use `--output=traceur`.\n\nTo force the inclusion of a specific test check, use `--enable` and specify the name (matching the test result name from this *es-feature-tests* library). To exclude a specific test check, use `--disable` and specify the matching name.\n\nSuppress errors for missing scan files with `--ignore-missing` and for invalid files (failure to parse the JS) with `--ignore-invalid`.\n\n### Testify Library\n\n`testify` can also be used programmatically in JS:\n\n```js\nvar testify = require(\"es-feature-tests/testify\"),\n\tcode = testify.scan({ ..options.. });\n\n// (Optional) To use the function inside Node:\nvar checkFeatureTests = new Function(\n\t\"res\",\n\tcode + \";return checkFeatureTests(res)\"\n);\n```\n\nThe options correspond similarly to the CLI parameters described above:\n\n* `files` (`string`, `array`): specifies file(s) to scan\n* `dirs` (`string`, `array`): specifies director(ies) of file(s) to scan\n* `excludes` (`string`, `array`): specifies exclusion pattern(s)\n* `content` (`string`): specifies text to scan as if it was already read from a file\n* `output` (`string`: `\"simple\"`, `\"json\"`, `\"babel\"`, `\"traceur\"`): controls the output formatting of the list of tests needed\n\n   **Note:** The CLI `--output` option defaults to `\"simple\"` (the code for `checkFeatureTests(..)`), but the default value for the library option is `\"json\"`, which *actually produces the array object itself, since that will likely be more useful when used programmatically.\n* `enabled` (`string`, `array`): specifies test(s) that should always be included\n* `disabled` (`string`, `array`): specifies test(s) that should never be included\n* `recursive` (`boolean`, default: `false`): make directory scans recursive\n* `ignore` (`object`, `boolean`): if `true`/`false`, will set all sub-properties accordingly; otherwise, should be an object with one or more of these:\n  - `ignore.missing` (`boolean`): ignore files or directories not found\n  - `ignore.invalid` (`boolean`): ignore files where the scan fails\n\n**Note:** `files`, `dirs`, and `excludes` all have the -`s` suffix, and `enabled` and `disabled` both have the -`d` suffix. However, the associated CLI parameter names do not have these suffixes.\n\n## GitHub\n\nIf you install this package from GitHub instead of npm, you won't have the `deploy/*` files for deployment. Run these commands from the main repo directory to build them:\n\n```\nnpm install\nnpm run build\n```\n\n## License\n\nThe code and all the documentation are all (c) 2015 Kyle Simpson and released under the MIT license.\n\nhttp://getify.mit-license.org/\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgetify%2FES-Feature-Tests","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgetify%2FES-Feature-Tests","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgetify%2FES-Feature-Tests/lists"}