{"id":20129383,"url":"https://github.com/ryanmorr/tagged","last_synced_at":"2025-10-18T12:38:14.040Z","repository":{"id":70575170,"uuid":"136649621","full_name":"ryanmorr/tagged","owner":"ryanmorr","description":"A tiny utility function for creating tagged template literals","archived":false,"fork":false,"pushed_at":"2024-10-21T16:46:38.000Z","size":168,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T16:09:38.243Z","etag":null,"topics":["javacript","tagged-template-literals","utility"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ryanmorr.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-08T17:48:14.000Z","updated_at":"2024-10-21T16:46:42.000Z","dependencies_parsed_at":"2024-10-21T22:23:23.511Z","dependency_job_id":null,"html_url":"https://github.com/ryanmorr/tagged","commit_stats":{"total_commits":27,"total_committers":1,"mean_commits":27.0,"dds":0.0,"last_synced_commit":"0be8c12b4ddfecec79fa0e5f9ac4d19a1e5da56f"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanmorr%2Ftagged","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanmorr%2Ftagged/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanmorr%2Ftagged/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanmorr%2Ftagged/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryanmorr","download_url":"https://codeload.github.com/ryanmorr/tagged/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248065283,"owners_count":21041871,"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":["javacript","tagged-template-literals","utility"],"created_at":"2024-11-13T20:34:01.801Z","updated_at":"2025-10-18T12:38:13.934Z","avatar_url":"https://github.com/ryanmorr.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tagged\n\n[![Version Badge][version-image]][project-url]\n[![License][license-image]][license-url]\n[![Build Status][build-image]][build-url]\n\n\u003e A tiny utility function for creating tagged template literals.\n\n## Install\n\nDownload the [CJS](https://github.com/ryanmorr/tagged/raw/master/dist/cjs/tagged.js), [ESM](https://github.com/ryanmorr/tagged/raw/master/dist/esm/tagged.js), [UMD](https://github.com/ryanmorr/tagged/raw/master/dist/umd/tagged.js) versions or install via NPM:\n\n``` sh\nnpm install @ryanmorr/tagged\n```\n\n## Usage\n\nInvoke with a function to handle the resulting template string:\n\n``` javascript\nconst fn = tagged((str) =\u003e str + ' bar');\n\nfn`foo`; //=\u003e \"foo bar\"\n```\n\nOptionally provide a second function to mutate values passed to the tagged template:\n\n``` javascript\nconst fn = tagged((str) =\u003e str, (val) =\u003e val.toLocaleDateString());\n\nfn`The date is ${new Date()}`; //=\u003e \"The date is 07/06/2018\"\n```\n\n## Examples\n\nLog to the console:\n\n``` javascript\nconst log = tagged((msg) =\u003e console.log(msg));\n\nlog`This is an imporant message`;\n```\n\nThrow an error:\n\n``` javascript\nconst error = tagged((msg) =\u003e {\n    throw new Error(msg);\n});\n\nconst code = 404;\nconst msg = 'Not found';\n\nerror`Network error: ${code} ${msg}`;\n```\n\nParse an HTML string into a document fragment:\n\n``` javascript\nconst toDOM = tagged((html) =\u003e {\n    const template = document.createElement('template');\n    template.innerHTML = html;\n    return document.importNode(template.content, true);\n});\n\nconst title = '\u003ch1\u003eHello World\u003c/h1\u003e';\n\nconst frag = toDOM`\u003cdiv\u003e${title}\u003c/div\u003e`;\n```\n\nCompose regular expressions:\n\n``` javascript\nconst regex = tagged((source) =\u003e new RegExp(source), (val) =\u003e val.source);\n\nconst yearRe = /([0-9]{4})/;\nconst monthRe = /([0-9]{2})/;\nconst dayRe = /([0-9]{2})/;\nconst dateRe = regex`^${yearRe}-${monthRe}-${dayRe}$`;\n\ndateRe.test('2018-01-10'); //=\u003e true\n```\n\nEncode parameters for a URI string:\n\n``` javascript\nconst uri = tagged((str) =\u003e str, encodeURIComponent);\n\nconst genre = 'rock \u0026 roll';\nconst artist = 'led zeppelin';\n\nuri`/genre/${genre}/artist/${artist}`); //=\u003e \"/genre/rock%20%26%20roll/artist/led%20zeppelin\"\n```\n\n## License\n\nThis project is dedicated to the public domain as described by the [Unlicense](http://unlicense.org/).\n\n[project-url]: https://github.com/ryanmorr/tagged\n[version-image]: https://img.shields.io/github/package-json/v/ryanmorr/tagged?color=blue\u0026style=flat-square\n[build-url]: https://github.com/ryanmorr/tagged/actions\n[build-image]: https://img.shields.io/github/actions/workflow/status/ryanmorr/tagged/node.js.yml?style=flat-square\n[license-image]: https://img.shields.io/github/license/ryanmorr/tagged?color=blue\u0026style=flat-square\n[license-url]: UNLICENSE","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanmorr%2Ftagged","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryanmorr%2Ftagged","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanmorr%2Ftagged/lists"}