{"id":15598379,"url":"https://github.com/fluffynuts/karma-transform-preprocessor","last_synced_at":"2025-08-12T17:43:32.751Z","repository":{"id":57288587,"uuid":"85614631","full_name":"fluffynuts/karma-transform-preprocessor","owner":"fluffynuts","description":"A preprocessor plugin for karma to facilitate content transformations for any file served by the karma server","archived":false,"fork":false,"pushed_at":"2017-03-20T19:44:05.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-09T08:07:32.498Z","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":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fluffynuts.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}},"created_at":"2017-03-20T18:57:06.000Z","updated_at":"2019-09-28T00:23:47.000Z","dependencies_parsed_at":"2022-09-08T09:42:20.001Z","dependency_job_id":null,"html_url":"https://github.com/fluffynuts/karma-transform-preprocessor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fluffynuts/karma-transform-preprocessor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluffynuts%2Fkarma-transform-preprocessor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluffynuts%2Fkarma-transform-preprocessor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluffynuts%2Fkarma-transform-preprocessor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluffynuts%2Fkarma-transform-preprocessor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fluffynuts","download_url":"https://codeload.github.com/fluffynuts/karma-transform-preprocessor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluffynuts%2Fkarma-transform-preprocessor/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270108620,"owners_count":24528764,"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","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-10-03T01:38:43.697Z","updated_at":"2025-08-12T17:43:32.701Z","avatar_url":"https://github.com/fluffynuts.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# karma-transform-preprocessor\nA preprocessor plugin for karma to facilitate content transformations for any file served by the karma server\n\n## Why?\n\nBecause sometimes you just need to mangle a file before Karma should be allowed to get to it.\nMy specific use case was working around a third-party Polymer component which attempted to define\nthe `translate` function on itself. Apart from this conflicting with\nPolymer base, the bigger issue is that this conflicts with a property\navailable on DOM elements. Some browsers, like Chrome (at time of\nwriting) permit smashing DOM element properties. Others, like QtWebKit (ie, in PhantomJs) do not, resulting in esoteric errors.\n\nThis plugin allows me to rewrite the declaration all uses of\n`translate` to, for example, `__translate`, working around the\nissue of CI tests running through PhantomJS failing when they don't\nfail in Chrome.\n\nBut this preprocessor could be used for whatever you want -- perhaps\nrewriting urls in html or data in JSON structures. It's all up to you.\n\n## How to use?\n\n1. You will need to add `karma-transform-preprocessor` to your `plugins` declaration in karma.conf.js, if it exists (I prefer explicit declaration of plugins and if you declare one, you must declare all the ones you want to use).\n2. Add one or more `preprocessors` matchers, eg:\n```\npreprocessors: {\n  \"**/*.html\": \"transform\"\n}\n```\n3. Add one or more transformers to deal with your matches. Any files which are not matched are simply passed through unscathed. Transformers may be synchronous or asynchronous and are used preferentially by the order in which they are defined:\n```\ntransformConfig: {\n  transforms: [\n    { match: /template1.html$/, transform: s =\u003e {\n        return \"\u003cp\u003ethis is the new template1.html\u003c/p\u003e\";\n      }\n    },\n    { match: /template2.html$/, transform: s =\u003e {\n        return new Promise((resolve, reject) =\u003e {\n          resolve(\"\u003cp\u003ethis is the new template2.html\u003c/p\u003e\");\n        });\n      } \n    },\n    { match: /late2.html$/, transform: s =\u003e {\n        return \"this will not match template2.html as it has lower precedence\";\n      }\n    },\n}\n```\n\n## Licensing\nBSD 3 Clause. Basically, you can use it wherever you want for free. You can fork it, you can change it. You can even sell it. You just can't take credit for it.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluffynuts%2Fkarma-transform-preprocessor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffluffynuts%2Fkarma-transform-preprocessor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluffynuts%2Fkarma-transform-preprocessor/lists"}