{"id":15380937,"url":"https://github.com/educastellano/template-format","last_synced_at":"2025-04-15T18:42:56.366Z","repository":{"id":47973178,"uuid":"76038179","full_name":"educastellano/template-format","owner":"educastellano","description":"Simple string formatting with support for nested data","archived":false,"fork":false,"pushed_at":"2023-01-04T08:51:42.000Z","size":184,"stargazers_count":7,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T16:17:50.306Z","etag":null,"topics":["string","string-format","string-formatter","string-formatting","string-manipulation","template","template-string"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/educastellano.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-09T13:34:29.000Z","updated_at":"2025-02-18T13:46:28.000Z","dependencies_parsed_at":"2023-02-02T06:01:34.569Z","dependency_job_id":null,"html_url":"https://github.com/educastellano/template-format","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/educastellano%2Ftemplate-format","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/educastellano%2Ftemplate-format/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/educastellano%2Ftemplate-format/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/educastellano%2Ftemplate-format/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/educastellano","download_url":"https://codeload.github.com/educastellano/template-format/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249131330,"owners_count":21217725,"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":["string","string-format","string-formatter","string-formatting","string-manipulation","template","template-string"],"created_at":"2024-10-01T14:25:04.637Z","updated_at":"2025-04-15T18:42:56.347Z","avatar_url":"https://github.com/educastellano.png","language":"JavaScript","readme":"# template-format\n\nSimple string formatting with support for nested data.\n\n## Install\n\n    npm install template-format\n\n## Syntax\n\n```js\nconst formattedText = format(text, data, options={})\n```\n\nParameter                     | Type       | Default       | Description\n---                           | ---        | ---           | ---\n`text`                        | `string`   |               | Text to format\n`object`                      | `object`   |               | The object or array containing the data to be used for formatting.\n`options`                     | `object`   | `{}`          | **Optional** Extra options, read below.\n`options.regex`               | `regex`   | `/{(.*?)}/g`   | **Optional** Alternative regex for different format syntaxes *(i.e.: `Hello {{name}}!`)*. Must include the global match modifier (`g`).\n`options.skipUndefined`       | `object`   | `false`       | **Optional** Skips formatting parameters which are missing in the object, keeping the original text. Otherwise they'll be replaced by an empty string.\n`options.spreadToken`         | `string`   | `$n`          | **Optional** Token used on arrays to indicate that the following attributes have to be applied in each element (See example below).\n`options.spreadSeparator`     | `string`   | `,`           | **Optional** String used on arrays to separate of the formatting in each element.\n\n## Usage\n\n```js\nimport format from 'template-format'\n```\n\n**With objects**\n\n```js\nformat('Hello {name}, happy {age} bday!', { name: 'Bob', age: 32 })\n// 'Hello Bob, happy 32 bday!'\n```\n\n**With arrays**\n\n```js\nformat('Hello {0}, happy {1} bday!', ['Bob', 32])\n// 'Hello Bob, happy 32 bday!'\n```\n\n**With nested data**\n\n```js\nformat('Hello {bob.name}, happy {bob.age} bday! I call you at {bob.contact.phone}', {\n        bob: {\n            name: 'Bob', \n            age: 32, \n            contact: {\n                phone: '978090909'\n            }\n        }\n    })\n// 'Hello Bob, happy 32 bday! I call you at 978090909'\n```\n\n**Spread arrays**\n\n```js\nformat('Hello {people.$n.name}!', { people: [{ name: 'Bob' }, { name: 'Mary' }] })\n// 'Hello Bob,Mary!'\n```\n\n**Other Options**\n\n* Skip undefined attributes:\n\n```js\nformat('Hello {name}, happy {age} bday!', { name: 'Bob' })\n// 'Hello Bob, happy bday!'\n```\n\n```js\nformat('Hello {name}, happy {age} bday!', { name: 'Bob' }, { skipUndefined: true })\n// 'Hello Bob, happy {age} bday!'\n```\n\n* Using a different format syntax:\n\n```js\nformat('Hello {{name}}, happy {{age}} bday!', { name: 'Bob', age: 32}, { regex: /{{(.*?)}}/g })\n// 'Hello Bob, happy 32 bday!'\n```\n\n* Custom spreading\n\n```js\nformat('Hello {people.$$.name}!', { people: [{ name: 'Bob' }, { name: 'Mary' }] }, { spreadToken: '$$', spreadSeparator: ', ' })\n// 'Hello Bob, Mary!'\n```\n\n## Changelog\n\n* 1.2.0\n    * Support to spread formatting on arrays\n    * Customizable spreading with `spreadToken` and `spreadSeparator`\n\n* 1.1.0\n    * Support to skip `undefined` attributes\n    * Support for alternative format syntaxes\n\n* 1.0.0 \n    * Initial release :tada:\n\n## License\n\n[ISC License](http://opensource.org/licenses/ISC)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feducastellano%2Ftemplate-format","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feducastellano%2Ftemplate-format","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feducastellano%2Ftemplate-format/lists"}