{"id":20865766,"url":"https://github.com/jhmaster2000/string-cook","last_synced_at":"2025-12-27T10:03:16.508Z","repository":{"id":262533984,"uuid":"622396629","full_name":"jhmaster2000/string-cook","owner":"jhmaster2000","description":"Cook (interpolate) raw template literal strings without unsafe dynamic code execution.","archived":false,"fork":false,"pushed_at":"2024-11-13T02:57:23.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-19T08:29:30.154Z","etag":null,"topics":["js","string-interpolation"],"latest_commit_sha":null,"homepage":"https://npm.im/string-cook","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/jhmaster2000.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":"2023-04-02T01:28:39.000Z","updated_at":"2024-11-13T02:57:26.000Z","dependencies_parsed_at":"2024-11-13T00:21:13.715Z","dependency_job_id":"a35f66b7-83ca-469d-bd16-d87224ea017a","html_url":"https://github.com/jhmaster2000/string-cook","commit_stats":null,"previous_names":["jhmaster2000/string-cook"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhmaster2000%2Fstring-cook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhmaster2000%2Fstring-cook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhmaster2000%2Fstring-cook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhmaster2000%2Fstring-cook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jhmaster2000","download_url":"https://codeload.github.com/jhmaster2000/string-cook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243238978,"owners_count":20259132,"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":["js","string-interpolation"],"created_at":"2024-11-18T05:54:38.141Z","updated_at":"2025-12-27T10:03:11.485Z","avatar_url":"https://github.com/jhmaster2000.png","language":"JavaScript","readme":"# string-cook\nCook (interpolate) raw template literal strings without unsafe dynamic code execution.\n\n## Example Usage\n- `sample.txt`\n```txt\nHello, ${user.name}!\\nYou are currently ${user.age} years old.\n```\n- `sample.js`\n```js\nimport cookString from 'string-cook';\nimport fs from 'fs';\n\nconst rawString = fs.readFileSync('sample.txt', 'utf8');\n// 'Hello, ${user.name}!\\\\nYou are currently ${user.age} years old.'\n\nconst user = { name: 'Bill', age: 27 };\nconst cooked = cookString(rawString, { user });\n// Hello, Bill!\n// You are currently 27 years old.\n\n/* Obviously, you can also pass strings directly from code rather than a file: */\nconst welcomeBack = 'Welcome back ${user.name}!';\nconst cooked2 = cookString(welcomeBack, { user });\n// Welcome back Bill!\n```\n\n## API\nThere is only one function:\n```ts\ncook(str: string, scope?: Record\u003cstring, unknown\u003e = {}): string\n```\nThis function is both the default export and a named export.\n\n* `str`: The input string to cook / interpolate.\n* `scope`: An object containing the variables which are exposed to the string interpolation. `${title}` on the input string will attempt to map to the value of a property named **title** in the `scope` object.\n    * Infinitely nested properties are supported, therefore the string `${foo.bar.baz}` is valid and maps to the value of **123** with an example `scope` object of `{ foo: { bar: { baz: 123 } } }`\n    * The `scope` object can contain properties not used by the input string.\n    * If the `scope` object does not contain a property used within the input string, the current behavior is to fallback to leaving the `${...}` text in place. (Proper error handling coming soon)\n    * The `scope` object is optional and can be empty or omitted.\n        * Cooking strings without a `scope` object is still useful to cook escape sequences, such as `\\\\n` (the `\\` character followed by `n`) to `\\n` (the newline character escape sequence)\n\n## Features and Limitations\n* Accurate to ECMAScript specification standards for valid identifiers. Invalid identifiers according to the spec are ignored. (Example: `${1invalid}`)\n* Only static object key identifiers **are supported**, any form of dynamic expression, such as `${user.age + 1}`, is **not supported** and will be ignored.\n* Indexed access syntax **is supported**, such as `${user['age']}` or `${user[\"age\"]}`\n    * Backtick ( **\\`** ) quotes in indexed access are **not supported**, since nested string cooking is **not supported** therefore it would serve no purpose.\n* Optional chaining access syntax **is supported**, such as `${user?.email}` or `${user?.['email']}`\n    * Currently, `?.` is parsed but treated identical to `.`, proper optional chaining behavior mimicking will come at a later update.\n* Unicode character escapes **are supported**, such as `${us\\u0065r}` or `${user['ag\\u0065']}`\n    * Unicode code point escapes (`\\u{000000}`) are **not supported** due to breaking the parsing of `${...}`\n    * Other character escapes, such as hex (`\\x00`) or octal (`\\0`) are **not supported** in identifiers as the spec disallows it. However they **are supported** in indexed access strings.\n* Array index access **is supported**, such as `${user.friends[0]}`\n    * The full JS numeric literal syntax **is supported**, this includes:\n        * Hex literals (`0x00`), octal literals (`0o00`) and binary literals (`0b00`)\n        * Scientific notation literals (`1e9`, `3E+7`, `2.7e-4`)\n        * Fractions (`.5`, `0.5`, `5.`, `5.0`, `967.830041`)\n        * Numeric separators (`1_500_000`, `0xFFFF_FFFF`)\n        * Unary `+` operator (`+42`)\n    * The following **unsupported** exceptions apply:\n        * Unary `-` operator / negative numbers (`-81`)\n        * The literals `Infinity`, `-Infinity` and `NaN`\n* Whitespace-insensivity **is supported**, such as `${   user  .    age }` is correctly parsed as `${user.age}`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjhmaster2000%2Fstring-cook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjhmaster2000%2Fstring-cook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjhmaster2000%2Fstring-cook/lists"}