{"id":21595189,"url":"https://github.com/euank/snailescape.js","last_synced_at":"2025-07-17T07:32:10.713Z","repository":{"id":57364495,"uuid":"44467161","full_name":"euank/snailescape.js","owner":"euank","description":"Javascript library to perform shell-like splitting and escaping of strings while respecting quoting","archived":false,"fork":false,"pushed_at":"2016-04-07T05:07:07.000Z","size":123,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-11T19:20:04.801Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/euank.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":"2015-10-18T05:46:25.000Z","updated_at":"2015-10-20T01:01:45.000Z","dependencies_parsed_at":"2022-09-13T21:11:21.581Z","dependency_job_id":null,"html_url":"https://github.com/euank/snailescape.js","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/euank/snailescape.js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euank%2Fsnailescape.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euank%2Fsnailescape.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euank%2Fsnailescape.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euank%2Fsnailescape.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/euank","download_url":"https://codeload.github.com/euank/snailescape.js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/euank%2Fsnailescape.js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265237636,"owners_count":23732513,"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-24T17:33:43.455Z","updated_at":"2025-07-17T07:32:10.672Z","avatar_url":"https://github.com/euank.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# snailescape.js :snail:\n\n[![Build Status](https://travis-ci.org/euank/snailescape.js.svg?branch=master)](https://travis-ci.org/euank/snailescape.js)\n[![Coverage Status](https://coveralls.io/repos/euank/snailescape.js/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/euank/snailescape.js?branch=master)\n\n\n[![Snail escape](/../imgs/header.png?raw=true \"Three lost snails\")](http://www.pixiv.net/member_illust.php?mode=medium\u0026illust_id=5469308)\n\nSnail escape is a simple javascript library that implements a sane subset of\nbash escaping, similar to the ANSI C standard for escapes.\n\n## Supported Quoting\n\nSingle quotes, double quotes, and space-separation of parts are supported. This is best explained through an example:\n\nAll of the following:\n\n`echo \"hello world\"`, `echo hello\\ world`, `\"echo\" 'hello world'`\n\nWill be split into:\n\n`[\"echo\", \"hello world\"]`\n\n## Supported Escapes\n\n* `\\a` \u0026mdash; Bell (`0x07`)\n* `\\b` \u0026mdash; Backspace (`0x08`)\n* `\\t` \u0026mdash; Tab (`0x09`)\n* `\\e` \u0026mdash; Escape (`0x1B`)\n* `\\n` \u0026mdash; Newline (`0x0A`)\n* `\\v` \u0026mdash; Vertical tab (`0x0B`)\n* `\\f` \u0026mdash; Form feed (`0x0C`)\n* `\\r` \u0026mdash; Carriage return (`0x0D`)\n* `\\ ` \u0026mdash; Space (`0x20`)\n* `\\\"` \u0026mdash; Double quote (`0x22`)\n* `\\'` \u0026mdash; Single quote (`0x27`)\n* `\\\\` \u0026mdash; Backslash (`0x5C`)\n* `\\[0-7]{1,3}` \u0026mdash; Octal ASCII character\n* `\\x[0-9a-f]{1,2}` \u0026mdash; Hex ASCII character\n\n### When escapes apply\n\nNone of the above escapes apply within single quotes.\nAll of the above escapes apply within double quotes or when not within quotes.\n\nEscaping a space character or single quote characer is entirely redundant\nwithin double quotes, but both may be done.\n\n## Error handling\n\n### Error index\n\nAny time the `error` field of the output is set, the `errorNdx` field is also\nset to an integer indicating what offset is erroneous.\n\n### Modes\n\nSnail escape has two modes of error handling:\n\nThis mode may be toggled by passing the argument `{partial: true}` to the\nconstructor. It defaults to false.\n\n#### Complete parse errors\n\nComplete parse errors operates under the assumption that the given string\nshould completely parse with no issues. It should have no trailing characters\nor mismatched quotes, and if it does that's an error.\n\n#### Partial parse errors\n\nPartial parse errors operates under the assumption that the string might be\nincomplete. this is useful if you are taking user-input as it is being typed\nand parsing it.\n\nIn this mode, it will return both an error and a 'complete' value. It is\npossible for a parse to be marked as not complete, and also not having any\nerrors. If a parse is marked as incomplete and does have errors, that means\nthere is no way for any added characters to make the arguments valid (e.g. if\nthere is an invalid escape sequence).\n\nIn this mode, you *must* check both `complete` and `error` before you may safeuly use the result.\n\n```javascript\nvar result = parser.parse('\"incomplete');\nif(result.complete \u0026\u0026 !result.error) {\n  // okay to use result.parts\n}\n```\n\n## Usage\n\n### In regular mode\n\n```javascript\nvar parser = new SnailEscape();\nvar result = parser.parse(\"echo hello world\");\nif(result.error) {\n  console.error(\"could not parse input: \", result.error);\n} else {\n  console.log(\"All done! You typed the below array (as json): \")\n  console.log(JSON.stringify(result.parts));\n}\n\n```\n\n### In partial mode\n\n```javascript\nvar parser = new SnailEscape({partial: true});\nvar result = parser.parse(\"'arg1' 'arg\\\\n2' arg\\\\n3 arg4 arg5\");\nif(result.error) {\n  console.log(\"This will never parse! Backspace now (starting at character \" + result.error.index);\n} else if(!result.complete) {\n  console.log(\"Keep typing...\");\n} else if(result.complete \u0026\u0026 !result.error) {\n  console.log(\"All done! You typed the below array (as json): \")\n  console.log(JSON.stringify(result.parts));\n}\n```\n\n## Known issues\n\n* In partial mode, mismatched quotes indicate the end of the string as erroneous, not the opening quote.\n* High unicode cannot be represented via escapes, only via the actual characters.\n\n## Contributions\n\nWelcome, though please add tests and make sure that `npm test` passes.\n\n## License\n\nApache 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feuank%2Fsnailescape.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feuank%2Fsnailescape.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feuank%2Fsnailescape.js/lists"}