{"id":21401448,"url":"https://github.com/spoonx/censoring","last_synced_at":"2025-07-13T21:31:47.575Z","repository":{"id":20335873,"uuid":"23610391","full_name":"SpoonX/Censoring","owner":"SpoonX","description":"Censor or highlight words and other patterns intelligently.","archived":false,"fork":false,"pushed_at":"2023-10-04T07:39:09.000Z","size":44,"stargazers_count":15,"open_issues_count":2,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-09T04:12:14.607Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://spoonx.github.io/Censoring","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/SpoonX.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":"2014-09-03T07:12:07.000Z","updated_at":"2023-10-04T06:59:40.000Z","dependencies_parsed_at":"2024-06-21T07:11:43.167Z","dependency_job_id":null,"html_url":"https://github.com/SpoonX/Censoring","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpoonX%2FCensoring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpoonX%2FCensoring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpoonX%2FCensoring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpoonX%2FCensoring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SpoonX","download_url":"https://codeload.github.com/SpoonX/Censoring/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225919521,"owners_count":17545275,"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-11-22T15:27:51.510Z","updated_at":"2024-11-22T15:27:52.011Z","avatar_url":"https://github.com/SpoonX.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Censoring\nThis module allows you to detect patterns in texts, even when attempted to be hidden and then either highlight (markup) or censor (replace) them.\nIt checks for upper casing, lower casing, 1337 replacements, or s,p-l.'i*t.\n\n**Note:** This module works in the browser as a global, or AMD module, as well as in node.js.\n\n## Example:\n\n```javascript\nvar Censoring    = require('censoring'),\n    scan         = new Censoring(),\n    testSentence = '';\n\n// Enable filters we want to use\nscan.enableFilters(['phone_number', 'email_address', 'words']);\n\n// Word\ntestSentence += 'The 1nt3r.n.e.t will not be censored! ';\n\n// Phone number\ntestSentence += 'Call me on 555-123456';\n\n// Email address\ntestSentence += ', or send an email to me[at]example(dot)com.';\n\n// Let's make the word internet illegal.\nscan.addFilterWord('internet');\n\n// Tell the scanner we're done, and it can prepare the results.\nscan.prepare(testSentence);\n\n// Did we have a match?\nif (scan.test()) {\n  console.log(\n    'We had a match! Here it is, but censored:',\n    scan.replace()\n  );\n\n  // The *** will not be censored! Call me on ***, or send an email to ***.\n}\n```\n\n\n## Installation\n`npm install --save censoring`\n\n## Filters\n\n| Pattern       | Description                              |\n| :------------ | :----------------------------------------|\n| long_number   | Matches long, consecutive numbers        |\n| phone_number  | Matches phone numbers.                   |\n| email_address | Matches email addresses in many formats. |\n| url           | Matches URL patterns.                    |\n| words         | Finds words, even when in disguise.      |\n\n## Methods\nA `Censoring` instance has the following methods.\n\n### .enableFilter(string filterName)\nEnable a filter from the list of filters. By default, they're all disabled.\n\n```javascript\nvar scan = new Censoring();\n\nscan.enableFilter('email_address');\n```\n\n### .enableFilters(Array filterNames)\nEnable multiple filters from the list of filters. By default, they're all disabled.\n\n```javascript\nvar scan = new Censoring();\n\nscan.enableFilters(['phone_number', 'email_address']);\n```\n\n### .disableFilter(string filterName)\nDisable a previously enabled filter.\n\n```javascript\nvar scan = new Censoring();\n\nscan.enableFilter('email_address');\nscan.disableFilter('email_address');\n```\n\n### .addFilterWords(Array filterWords)\nAdd multiple words to filter on.\n\n```javascript\nvar scan = new Censoring();\n\nscan.enableFilter('words');\nscan.addFilterWords(['stoopid head', 'big meany']);\n```\n\n### .addFilterWord(string filterWord)\nAdd a word to filter on.\n\n```javascript\nvar scan = new Censoring();\n\nscan.enableFilter('words');\nscan.addFilterWord('doody face');\n```\n\n### .setReplacementString(string|function(match: string):string replacementString)\nSet a replacement function, or set a string to replace matches with. Defaults to `***`.\n\n```javascript\nvar scan = new Censoring();\n\nscan.setReplacementString('pony');\nscan.setReplacementString((match) =\u003e '*'.repeat(match.length));\n```\n\n### .getReplacementString()\nGet the currently set replacement string.\n\n```javascript\nvar scan = new Censoring();\n\nscan.getReplacementString(); // Returns '***'\n```\n\n### .setHighlightColor(string hexCode)\nSet the color for highlighted occurrences. Defaults to `#F2B8B8`.\n\n```javascript\nvar scan = new Censoring();\n\nscan.setHighlightColor('#ff0');\n```\n\n### .prepare(string inputString[, bool highlight])\nPrepare a string, and optionally supply `highlight` to not replace occurrences, but highlight them using html.\n\n```javascript\nvar scan = new Censoring();\n\nscan.enableFilter('email_address');\nscan.prepare('me@example[dot]com', true);\n```\n\n### .test()\nTest if the string you've prepared matches any of the filters.\n\n```javascript\nvar scan = new Censoring();\n\nscan.enableFilter('email_address');\nscan.prepare('me@example[dot]com');\n\nif (scan.test()) {\n  console.log('We have a match!');\n}\n```\n\n### .replace()\nReplace all occurrences found in the prepared string.\n\n\u003e Note: This will return HTML with the matches highlighted if the scan was prepared with .prepare(txt, true).\n\n```javascript\nvar scan = new Censoring();\n\nscan.enableFilter('email_address');\nscan.prepare('Email me at me@example[dot]com');\n\nconsole.log(scan.replace());\n// Outputs: Email me at ***\n```\n\n### .filterString(string inputString[, bool highlight])\nFilter a string directly, without preparing it first.\n\n\u003e Note: Bad for performance When combined with `.test()` and `.replace`.\n\n```javascript\nvar scan = new Censoring(),\n    testString = \"I'm going to tell mommy that you're a big meany!\",\n    result;\n\nscan.enableFilter('words');\nscan.addFilterWords(['stoopid head', 'big meany']);\n\nresult = scan.filterString(testString);\n\nconsole.log(result);\n// Outputs: I'm going to tell mommy that you're a ***!\n```\n\n### .addFilter(string name)\nAdd a new filter. A filter is essentially a `name` and a `pattern`.\n\n```javascript\nvar scan = new Censoring();\n\nscan.addFilter('bigot', {\n    enabled: true,\n    pattern: /^I'm not a racist,? but/\n});\n```\n\n## Support / contributing\nIf you have any questions or feature requests (such as publishing on bower..?) you can:\n\n* Check out the issues\n* Join us on freenode (#spoonx)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspoonx%2Fcensoring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspoonx%2Fcensoring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspoonx%2Fcensoring/lists"}