{"id":20692063,"url":"https://github.com/richie-south/javascript-rich-string-parser","last_synced_at":"2025-04-22T17:04:15.670Z","repository":{"id":86918058,"uuid":"401695300","full_name":"richie-south/javascript-rich-string-parser","owner":"richie-south","description":"Find tokens in your strings","archived":false,"fork":false,"pushed_at":"2025-03-21T08:36:28.000Z","size":360,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T17:02:04.917Z","etag":null,"topics":["parser","string-parser","string-parsing"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/richie-south.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}},"created_at":"2021-08-31T12:29:30.000Z","updated_at":"2025-03-21T08:36:32.000Z","dependencies_parsed_at":"2023-03-13T19:49:16.840Z","dependency_job_id":"3053e175-cf69-4c95-8bd7-82a7c729e39d","html_url":"https://github.com/richie-south/javascript-rich-string-parser","commit_stats":{"total_commits":42,"total_committers":1,"mean_commits":42.0,"dds":0.0,"last_synced_commit":"4f8cd9a63aa00cbc0a25efecc6fe149749869515"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richie-south%2Fjavascript-rich-string-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richie-south%2Fjavascript-rich-string-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richie-south%2Fjavascript-rich-string-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richie-south%2Fjavascript-rich-string-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/richie-south","download_url":"https://codeload.github.com/richie-south/javascript-rich-string-parser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250285650,"owners_count":21405296,"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":["parser","string-parser","string-parsing"],"created_at":"2024-11-16T23:19:01.222Z","updated_at":"2025-04-22T17:04:15.648Z","avatar_url":"https://github.com/richie-south.png","language":"TypeScript","readme":"# rich-string-parser\n\nFinds rich text in strings, ex: links, mentions, emails, your own parser, in an non overlapping way to prevent dubble matching.\n\n**Example**\n\n```typescript\nimport {richStringParser} from 'rich-string-parser'\nimport {emailParser} from 'rich-string-parser/lib/parsers/email-parser'\nimport {linkParser} from 'rich-string-parser/lib/parsers/link-parser'\n\nconst result = richStringParser(\n  'https://www.typescriptlang.org/ text example@example.com more text',\n  [emailParser(), linkParser()],\n)\n\n// log result\n/* [\n  {\n    type: 'LinkParser',\n    match: 'https://www.typescriptlang.org/',\n    index: 0,\n    subIndex: 0\n  },\n  ' text ',\n  {\n    type: 'EmailParser',\n    match: 'example@example.com',\n    index: 37,\n    subIndex: 37\n  },\n  ' more text'\n] */\n```\n\n## Parser result\n\nrequired parameters\n\n```jsonc\n{\n  \"type\": \"\", // uniq for each parser\n  \"match\": \"\", // result from parser\n  \"index\": 0, // where match is found based on whole string\n  \"subIndex\": 0 // where match is found based on parsed substring\n}\n```\n\n## Built in parsers\n\n**MentionParser**\n\nMatches on `@(number|string)`, @(9712|John)\n\nResult:\n\nWithout mention type:\n\n```typescript\n{\n  type: 'MentionParser',\n  match: '@(9712|John)',\n  id: 9712,\n  name: 'John',\n  index: 0,\n  subIndex: 0,\n  target: undefined\n}\n```\n\nWith mention type provided:\n\n```typescript\n{\n  type: 'MentionParser',\n  match: '@(0|Testgroupchatroom|group)',\n  id: 0,\n  name: 'Testgroupchatroom',\n  index: 0,\n  subIndex: 0,\n  target: 'group'\n}\n```\n\n**EmailParser**\n\nMatches on `example@example.com`,\n\nResult:\n\n```typescript\n{\n  type: 'EmailParser',\n  match: 'example@example.com',\n  index: 0,\n  subIndex: 0,\n}\n```\n\n**LinkParser**\n\nMatches on `https://example.com`,\n\nResult:\n\n```typescript\n{\n  type: 'LinkParser',\n  match: 'https://example.com',\n  index: 0,\n  subIndex: 0,\n}\n```\n\n## Create your own parser\n\nCreate a function that retrurns a `Parser` interface with a custom string in generic type, example `Parser\u003c'HashtagParser'\u003e`.\nImplemente the required return object function `parse`.\n\n**Example**\n\n```typescript\nfunction hashtagParser(): Parser\u003c'HashtagParser'\u003e {\n  const regex: RegExp = /(#[a-z\\d-]+)/gi\n\n  return {\n    parse: (text, index) =\u003e {\n      const result = regex.exec(text)\n      if (result === null) return null\n\n      return {\n        type: 'HashtagParser',\n        match: result[0],\n        index: index + result.index, // don't forget to add the global index\n        subIndex: result.index,\n      }\n    },\n  }\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichie-south%2Fjavascript-rich-string-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frichie-south%2Fjavascript-rich-string-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichie-south%2Fjavascript-rich-string-parser/lists"}