{"id":16485350,"url":"https://github.com/morganconrad/metalsmith-select","last_synced_at":"2025-02-28T22:41:09.662Z","repository":{"id":71409913,"uuid":"107019389","full_name":"MorganConrad/metalsmith-select","owner":"MorganConrad","description":"Temporarily process a subset of Metalsmith files with other plugins","archived":false,"fork":false,"pushed_at":"2020-04-25T23:24:51.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-11T14:45:57.523Z","etag":null,"topics":["filter","metalsmith-plugin","subset"],"latest_commit_sha":null,"homepage":"","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/MorganConrad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-15T14:26:30.000Z","updated_at":"2020-10-22T00:07:07.000Z","dependencies_parsed_at":"2023-03-17T11:15:33.863Z","dependency_job_id":null,"html_url":"https://github.com/MorganConrad/metalsmith-select","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MorganConrad%2Fmetalsmith-select","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MorganConrad%2Fmetalsmith-select/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MorganConrad%2Fmetalsmith-select/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MorganConrad%2Fmetalsmith-select/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MorganConrad","download_url":"https://codeload.github.com/MorganConrad/metalsmith-select/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241261902,"owners_count":19936046,"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":["filter","metalsmith-plugin","subset"],"created_at":"2024-10-11T13:25:31.641Z","updated_at":"2025-02-28T22:41:09.638Z","avatar_url":"https://github.com/MorganConrad.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://secure.travis-ci.org/MorganConrad/metalsmith-select.png)](http://travis-ci.org/MorganConrad/metalsmith-select)\n[![License](http://img.shields.io/badge/license-MIT-A31F34.svg)](https://github.com/MorganConrad/metalsmith-select)\n[![NPM Downloads](http://img.shields.io/npm/dm/metalsmith-select.svg)](https://www.npmjs.org/package/metalsmith-select)\n[![Known Vulnerabilities](https://snyk.io/test/github/morganconrad/metalsmith-select/badge.svg)](https://snyk.io/test/github/morganconrad/metalsmith-select)\n[![Coverage Status](https://coveralls.io/repos/github/MorganConrad/metalsmith-select/badge.svg)](https://coveralls.io/github/MorganConrad/metalsmith-select)\n\n# metalsmith-select\nCreates (\"selects\") a temporary subset of Metalsmith's filedata, on which you can use plugins.  Then call `done()` to return to normal flow with all files.  Useful if your plugins are very long, expensive, or conflicting.\n\n**Warning**: If the plugins add or remove \"files\", **this wil not work**.  It does work if they modify existing files, metalsmith, etc...\n\nFunctional Programmers might think of this as \"`filter().forEach()`\", but, unlike modules like [metalsmith-filter](https://www.npmjs.com/package/metalsmith-filter) it does not permanently change the original files object.\n\nProcedural Programmers could think of this as \"`if/then/else`\": for all files, if they pass the selection criteria, then use the plugins.\n\n```\nconst select = require('metalsmith-select');\n  ...\n.use(select(options))           // select a subset of files\n  .thenUse(plugin1(options1))   // plugin1 uses the subset\n  .thenUse(plugin2(options2))   // as does plugin2\n  .elseUse(yaPlugin(yaOptions)) // rejected files go through yaPlugin\n  .done()\n.use(...)                       // back to original flow with full set of files\n```\n\n### options\n\nDue to the special nature of this plugin, Javascript only, no CLI. (???)  \n\nUsually **options** is an object of key/testCriteria properties, e.g.\n ```\n{\n   key1: testCriteria1,\n   key2: testCriteria2\n}\n```\nFor each property, `let valueToBeTested = fileData[key];`  **Exception**: when the key is `__filename__`, use the filename.\n\nThe selection test depends on testCriteria.\n\u003cpre\u003e\n boolean : whether valueToBeTested exists (or not)\n RegExp  : RegExp.test(valueToBeTested)\n String  : convert String to a RegExp and .test(valueToBeTested)\n function: testCriteria(valueToBeTested, metalsmith)\n\u003c/pre\u003e\n\nFiles that pass **all** of the tests get passed to `thenUse()`.\u003cbr\u003e  Rejected files get passed to `elseUse()`.\n\nIf **options** is null or {}, all files are accepted, say, if you want to use [metalsmith-filter](https://www.npmjs.com/package/metalsmith-filter) instead.\n\nIf **options** is a function, the selection criteria is `options(fileData, metalsmith)`.  This gives you complete control for offbeat cases.\n\n### Notes, Todos, and Caveats\n\nSide Effect:  **select** adds a `__filename__` property to every file object.\n\nTo simulate an OR, just `use(select())` twice:\n\n```\nuse(select(options_left_half_of_OR))\n  .thenUse(somePlugin(itsOptions))\n.use(select((options_right_half_of_OR))\n  .thenUse(somePlugin(itsOptions))\n```\n\nI haven't tested `select` all that much in practice, and it's doing tricky stuff, so beware.\n\n### Examples\n\nOnly pass files with a field \"usePrismJS\" to metalsmith-prism\n\n```\nuse(select({ usePrismJS: true })\n  .thenUse(metalsmithPrism())\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorganconrad%2Fmetalsmith-select","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorganconrad%2Fmetalsmith-select","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorganconrad%2Fmetalsmith-select/lists"}