{"id":15379909,"url":"https://github.com/iansan5653/unraw","last_synced_at":"2025-04-15T06:12:51.992Z","repository":{"id":35773985,"uuid":"200283113","full_name":"iansan5653/unraw","owner":"iansan5653","description":"🔄 Reverse of JavaScript's `String.raw` API.","archived":false,"fork":false,"pushed_at":"2024-06-16T10:30:17.000Z","size":337,"stargazers_count":25,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-15T06:12:43.814Z","etag":null,"topics":["escape-sequence","escape-sequences","javascript","raw-strings","string-manipulation","typescript","unescape","unicode"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/unraw","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/iansan5653.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"security.md","support":null}},"created_at":"2019-08-02T18:48:46.000Z","updated_at":"2025-02-19T10:33:27.000Z","dependencies_parsed_at":"2023-01-16T06:06:37.645Z","dependency_job_id":null,"html_url":"https://github.com/iansan5653/unraw","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iansan5653%2Funraw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iansan5653%2Funraw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iansan5653%2Funraw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iansan5653%2Funraw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iansan5653","download_url":"https://codeload.github.com/iansan5653/unraw/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249016638,"owners_count":21198833,"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":["escape-sequence","escape-sequences","javascript","raw-strings","string-manipulation","typescript","unescape","unicode"],"created_at":"2024-10-01T14:20:19.757Z","updated_at":"2025-04-15T06:12:51.972Z","avatar_url":"https://github.com/iansan5653.png","language":"TypeScript","readme":"# `unraw`\n\n```ts\nunraw(\"\\\\'\\\\t\\\\u{1f601}\\\\'\"); // -\u003e \"'\t😁'\"\n```\n\n`unraw` is a small module that converts raw strings to parsed strings in the same\nmanner as the standard JavaScript escaping engine. In essence, it is the exact\nopposite of\n[`String.raw`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw).\n\n## Use Case\n\nMost of the time, you probably don't need this library unless you're working\ndirectly with raw strings and you need a way to get them back to normal strings.\nMaybe the most signicant use case is when building\n[template literal tags](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates);\nyou can use the `.raw` property of the passed string array to access the raw\nstrings, but then you may want to still return normal strings after processing.\n\nThe module is also useful for parsing text files written with escape sequences,\nalthough keep in mind that the JavaScript flavor of escape sequences may differ\nfrom the flavor used in an input file.\n\n## Getting Started\n\n`unraw` is a UMD module, so it can be used in Node or on the web. Typings are\nincluded for TypeScript as well.\n\n### Usage in Node.JS\n\n`unraw` is hosted on [npm](https://www.npmjs.com/unraw), so you can install\nwith:\n\n```bash\nnpm i unraw\n```\n\nTo use in code:\n\n```js\nimport unraw from \"unraw\";\n\nunraw(\"\\\\n\");\n```\n\nIf you want to access error messages:\n\n```js\nimport {unraw, errorMessages, ErrorType} from \"unraw\";\n\nunraw(\"\\\\n\");\nerrorMessages.get(ErrorType.MalformedUnicode);\n```\n\n## Usage\n\nUsage is simple - the library exports a default function, `unraw`. The first\nargument to `unraw` is the string to parse, and the second is an optional flag\nto allow or disallow octal escapes, which are deprecated (defaults to\n`false`, so the default behavior is to throw an error when octal sequences\nare encountered).\n\n```js\nunraw(\"\\\\t\\\\tThis is indented.\");\n// =\u003e \"\t\tThis is indented.\"\n```\n\nThe library attempts to mimic the behaviour of standard JavaScript strings as\nclosely as possible. This means that invalid escape sequences will throw\n`SyntaxError`s and that every escape sequence that is valid in a normal string\nshould be valid when passed to `unraw`.\n\nIn some ways this is similar to the behavior of `JSON.parse`.\n\nYou can always expect the outcome of calling `unraw` on a raw string to be\nexactly the same as if that string were not raw in the first place:\n\n```js\n`Invalid: \\u23`                   // Throws a SyntaxError\nunraw(String.raw`Invalid: \\u23`)  // Throws a SyntaxError\n\n`Valid: \\u0041`                   // =\u003e `Valid: A`\nunraw(String.raw`Valid: \\u0041`)  // =\u003e `Valid: A`\n\n`Valid: \\A`                       // =\u003e `Valid: A`\nunraw(String.raw`Valid: \\A`)      // =\u003e `Valid: A`\n\n`Valid: \\\\`                       // =\u003e `Valid: \\`\nunraw(String.raw`Valid: \\\\`)      // =\u003e `Valid: \\`\n\n`Valid: \\x42`                     // =\u003e `Valid: B`\nunraw(String.raw`Valid: \\x42`)    // =\u003e `Valid: B`\n\n`Octal: \\102`                      // =\u003e Throws a SyntaxError\nunraw(String.raw`Octal: \\102`)     // =\u003e Throws a SyntaxError\nunraw(String.raw`Octal: \\102`, true) // =\u003e Octal: B\n```\n\n### Errors\n\nIf desired, you can access the possible error messages to help identify errors:\n\n```ts\nimport {unraw, ErrorType, errorMessages} from \"unraw\";\n\ntry {\n  unraw(\"\\\\u25\");\n} catch (err) {\n  if (err.message === errorMessages.get(ErrorType.MalformedUnicode)) {\n    console.error(\"String had an invalid Unicode escape sequence.\");\n  }\n}\n```\n\nThe full list of error message names available through the `ErrorType` enum\n(exposed as a normal object in JavaScript).\n\n## Contributing\n\nFound a bug? Please,\n[submit it here.](https://github.com/iansan5653/unraw/issues)\n\nPull requests are always welcome, although to increase your chances of your\ncontribution being accepted, opening an issue and linking to it is always a\ngood idea.\n\nPull requests will not be merged unless the GitHub Actions build succeeds.\nThis means that all checks must pass and code must be free of lint errors. To\nquickly confirm that it will, just run:\n\n```bash\nnpm run check\n```\n\nThis checks your formatting, tests, and for TypeScript compiler errors. If the\ntask doesn't fail, you should be good to go.\n\n### Other Tasks\n\nFor your convenience, some other tasks are also provided in the `package.json`:\n\n- `npm run build` - Compiles TypeScript code to JavaScript\n- `npm run minify` - Generate minified JavaScript files from compiled files\n- `npm run test` - Quickly run tests using TypeScript code without compiling\n- `npm run lint` - Check code for linting errors\n- `npm run check` - Check to ensure code will pass Pipelines checks (see above)\n- `npm run format` - Format code using Prettier\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiansan5653%2Funraw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiansan5653%2Funraw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiansan5653%2Funraw/lists"}