{"id":15026748,"url":"https://github.com/polyfillpolyfill/polyfill-library","last_synced_at":"2025-04-04T13:09:51.977Z","repository":{"id":224209907,"uuid":"762719221","full_name":"polyfillpolyfill/polyfill-library","owner":"polyfillpolyfill","description":"NodeJS module to create polyfill bundles tailored to individual user-agents.","archived":false,"fork":false,"pushed_at":"2024-02-24T14:09:43.000Z","size":816,"stargazers_count":678,"open_issues_count":0,"forks_count":103,"subscribers_count":85,"default_branch":"main","last_synced_at":"2025-03-28T12:05:04.740Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polyfillpolyfill.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-24T13:59:52.000Z","updated_at":"2025-03-20T03:43:55.000Z","dependencies_parsed_at":"2024-02-24T15:17:09.864Z","dependency_job_id":null,"html_url":"https://github.com/polyfillpolyfill/polyfill-library","commit_stats":null,"previous_names":["polyfillpolyfill/polyfill-library"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyfillpolyfill%2Fpolyfill-library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyfillpolyfill%2Fpolyfill-library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyfillpolyfill%2Fpolyfill-library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyfillpolyfill%2Fpolyfill-library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polyfillpolyfill","download_url":"https://codeload.github.com/polyfillpolyfill/polyfill-library/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247181218,"owners_count":20897368,"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-09-24T20:05:00.985Z","updated_at":"2025-04-04T13:09:51.960Z","avatar_url":"https://github.com/polyfillpolyfill.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Polyfill-library \u0026middot; [![license][license-badge]][license] [![PRs Welcome][pull-requests-badge]][contributing-guide]\n\n\u003e NodeJS module to create polyfill bundles tailored to individual user-agents\n\n## Install\n\n```bash\nnpm install polyfill-library --save\n```\n\n## Usage\n\n```javascript\nconst polyfillLibrary = require('polyfill-library');\n\nconst polyfillBundle = polyfillLibrary.getPolyfillString({\n\tuaString: 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)',\n\tminify: true,\n\tfeatures: {\n\t\t'es6': { flags: ['gated'] }\n\t}\n}).then(function(bundleString) {\n\tconsole.log(bundleString);\n});\n```\n\n## API\n\n### `polyfillLibrary.listAllPolyfills()`\n\nGet a list of all the polyfills which exist within the collection of polyfill sources.\n\nReturns a Promise which resolves with an array of all the polyfills within the collection.\n\n### `polyfillLibrary.describePolyfill(featureName)`\n\nGet the metadata for a specific polyfill within the collection of polyfill sources.\n\n- `@param {String} featureName` - The name of a polyfill whose metadata should be returned.\n\nReturns a Promise which resolves with the metadata or with `undefined` if no metadata exists for the polyfill.\n\n### `polyfillLibrary.getOptions(opts = {})`\n\nCreate an options object for use with `getPolyfills` or `getPolyfillString`.\n\n- `@param {object} opts` - Valid keys are uaString, minify, unknown, excludes, rum and features.\n- `@param {Boolean} [opts.minify=true]` - Whether to return the minified or raw implementation of the polyfills.\n- `@param {'ignore'|'polyfill'} [opts.unknown='polyfill']` - Whether to return all polyfills or no polyfills if the user-agent is unknown or unsupported.\n- `@param {Object} [opts.features={}]` - Which features should be returned if the user-agent does not support them natively.\n- `@param {Array\u003cString\u003e} [opts.excludes=[]]` - Which features should be excluded from the returned object.\n- `@param {String} [opts.uaString='']` - The user-agent string to check each feature against.\n- `@param {Boolean} [opts.rum=false]` - Whether to include a script that reports anonymous usage data in the polyfill bundle.\n\nReturns an object which has merged `opts` with the defaults option values.\n\n### `polyfillLibrary.getPolyfills(opts)`\n\nGiven a set of features that should be polyfilled in 'opts.features' (with flags i.e. `{\u003cfeaturename\u003e: {flags:Set[\u003cflaglist\u003e]}, ...}`), determine which have a configuration valid for the given opts.uaString, and return a promise of set of canonical (unaliased) features (with flags) and polyfills.\n\n- `@param {object} opts` - Valid keys are uaString, minify, unknown, excludes, rum and features.\n- `@param {Boolean} [opts.minify=true]` - Whether to return the minified or raw implementation of the polyfills.\n- `@param {'ignore'|'polyfill'} [opts.unknown='polyfill']` - Whether to return all polyfills or no polyfills if the user-agent is unknown or unsupported.\n- `@param {Object} [opts.features={}]` - Which features should be returned if the user-agent does not support them natively.\n- `@param {Array\u003cString\u003e} [opts.excludes=[]]` - Which features should be excluded from the returned object.\n- `@param {String} [opts.uaString='']` - The user-agent string to check each feature against.\n- `@param {Boolean} [opts.rum=false]` - Whether to include a script that reports anonymous usage data in the polyfill bundle.\n\nReturns a Promise which resolves to an Object which contains the canonicalised feature definitions filtered for UA.\n\n### `polyfillLibrary.getPolyfillString(opts)`\n\nCreate a polyfill bundle.\n\n- `@param {object} opts` - Valid keys are uaString, minify, unknown, excludes, rum and features.\n- `@param {Boolean} [opts.minify=true]` - Whether to return the minified or raw implementation of the polyfills.\n- `@param {'ignore'|'polyfill'} [opts.unknown='polyfill']` - Whether to return all polyfills or no polyfills if the user-agent is unknown or unsupported.\n- `@param {Object} [opts.features={}]` - Which features should be returned if the user-agent does not support them natively.\n- `@param {Array\u003cString\u003e} [opts.excludes=[]]` - Which features should be excluded from the returned object.\n- `@param {String} [opts.uaString='']` - The user-agent string to check each feature against.\n- `@param {Boolean} [opts.rum=false]` - Whether to include a script that reports anonymous usage data in the polyfill bundle.\n- `@param {Boolean} [opts.stream=false]` - Whether to return a stream or a string of the polyfill bundle.\n\nReturns a polyfill bundle as either a utf-8 ReadStream or as a Promise of a utf-8 String.\n\n## AWS Lambda\n\nTo use this package in an AWS Lambda function, you need to include the distribution Polyfills located in `./node_modules/polyfill-library/polyfills/__dist` in the root directory of your Lambda. In AWS, Lambdas are executed in the `/var/task/...` directory. Therefore, during execution, the directory where the polyfills will be located will be `/var/task/polyfill-library/__dist`.\n\n### Example of a script to copy files\n\nThe following snippet will allow us to copy the polyfills to our already compiled Lambda. To do this, we will first install the necessary dependencies.\n\n```bash\nyarn add -D make-dir fs-extra\n```\n\nOnce the dependencies are installed, we will create the file with the script at `/scripts/polyfills-serverless.mjs` and replace `YOUR_BUNDELED_LAMBDA_DIRECTORY` with the directory that contains our packaged Lambda.\n\nIn the example, we will use the directory `./.serverless_nextjs/api-lambda`, which is the one used when using Serverless Next.js.\n\n```js\nimport { copySync } from 'fs-extra/esm';\nimport makeDir from 'make-dir';\n\nconst DIR_POLYFILLS = './node_modules/polyfill-library/polyfills/__dist';\n// const DIR_SERVERLESS = 'YOUR_BUNDELED_LAMBDA_DIRECTORY/polyfills/__dist';\nconst DIR_SERVERLESS = './.serverless_nextjs/api-lambda/polyfills/__dist';\n\nconst paths = await makeDir(DIR_SERVERLESS);\nconsole.log(`The directory ${paths} is created successfully.`);\n\ntry {\n  console.log('Copying polyfills to serverless directory...');\n  copySync(DIR_POLYFILLS, DIR_SERVERLESS, { overwrite: false });\n  console.log('Polyfills copied successfully!');\n} catch (err) {\n  console.error(err);\n}\n```\n\nTo execute the script, you will need to run the following command:\n\n```bash\nnode ./scripts/polyfills-serverless.mjs\n```\n\n## Contributing\n\nDevelopment of polyfill-library happens on GitHub. Read below to learn how you can take part in contributing to Polyfill.io.\n\n### [Contributing Guide][contributing-guide]\n\nRead our [contributing guide][contributing-guide] to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes.\n\n```\n# To test on BrowserStack you will need to have a BrowserStack account\n# We test pull-requests using BrowserStack\nnpm run test-all-polyfills # Run the tests for all polyfills using BrowserStack\nnpm run test-polyfills -- --features=Array.from # Run the tests for Array.from\nnpm run test-polyfills -- --features=Array.from --browserstack # Run the tests for Array.from using BrowserStack\n```\n\n### License\n\nPolyfill-library is [MIT licensed][license].\n\n[contributing-guide]: https://github.com/Financial-Times/polyfill-library/blob/master/.github/contributing.md\n[license]: https://github.com/Financial-Times/polyfill-library/blob/master/LICENSE.md\n[license-badge]: https://img.shields.io/badge/license-MIT-blue.svg\n[pull-requests-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolyfillpolyfill%2Fpolyfill-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolyfillpolyfill%2Fpolyfill-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolyfillpolyfill%2Fpolyfill-library/lists"}