{"id":15698888,"url":"https://github.com/doowb/strings","last_synced_at":"2025-07-27T11:38:32.319Z","repository":{"id":12376174,"uuid":"15027676","full_name":"doowb/strings","owner":"doowb","description":"Replace :props in strings, create simple regex parsers, store parsers and prop-strings and run them in any context.","archived":false,"fork":false,"pushed_at":"2014-07-04T01:11:34.000Z","size":544,"stargazers_count":6,"open_issues_count":3,"forks_count":0,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-02-26T10:51:20.348Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/doowb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-08T17:14:45.000Z","updated_at":"2022-04-14T13:36:02.000Z","dependencies_parsed_at":"2022-09-01T12:10:56.842Z","dependency_job_id":null,"html_url":"https://github.com/doowb/strings","commit_stats":null,"previous_names":["assemble/strings"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fstrings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fstrings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fstrings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fstrings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doowb","download_url":"https://codeload.github.com/doowb/strings/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243141270,"owners_count":20242815,"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-10-03T19:35:40.501Z","updated_at":"2025-03-12T01:37:53.817Z","avatar_url":"https://github.com/doowb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# strings [![NPM version](https://badge.fury.io/js/strings.png)](http://badge.fury.io/js/strings)\n\n\u003e Easily replace and transform :props in strings.\n\nStrings is the result of many hours on [screenhero](http://screenhero.com/) and a truly collaborative effort between [Brian Woodward](https://github.com/doowb) and [Jon Schlinkert](https://github.com/jonschlinkert).\n\nPlease [report any bugs or feature requests](https://github.com/assemble/strings/issues/new), thanks!\n\n## Install\n\n### [npm](npmjs.org)\n\n```bash\nnpm install strings --save\n```\n\n### [bower](https://github.com/bower/bower)\n\n```bash\nbower install strings --save\n```\n\n## API\n### Strings\n\n\u003e Strings constructor method\n\nCreate a new instance of `Strings`, optionally passing a default context to use.\n\n**Example**\n\n```js\nvar strings = new Strings({destbase: '_gh_pages/'});\n```\n \n* `return` {Object} Instance of a Strings object \n\n\n### .propstring\n\nSet or get a named propstring.\n\n```js\nstrings.propstring(name, propstring)\n```\n\n**Example**\n\n```js\nstrings.propstring('url', ':base/blog/posts/:basename:ext');\n```\n\n* `name` {String} \n* `propstring` {String}  \n* `return` {Strings} to allow chaining \n\n\n### .pattern\n\nSet or get a string or regex pattern to be used for matching.\n\n```js\nstrings.pattern(name, pattern, flags);\n```\n\n**Example**\n\n```js\nstrings.pattern('anyProp', ':([\\\\w]+)');\n```\n\n* `name` {String}: The name of the stored pattern. \n* `pattern` {String|RegExp|Function}: The pattern to use for matching. \n* `flags` {String}: Optionally pass RegExp flags to use.  \n* `return` {Strings} to allow chaining \n\n\n### .source\n\nReturn the RegExp source from a stored `pattern`.\n\n```js\nstrings.source(name);\n```\n\n**Example**\n\n```js\nstrings.pattern('foo', {re: /:([\\\\w]+)/gm});\nstrings.source('foo');\n//=\u003e ':([\\\\w]+)'\n```\n\n* `name` {String}: The name of the stored pattern.   \n\n\n### .replacement\n\nSet or get a replacement pattern. Replacement patterns can be a\nregular expression, string or function.\n\n```js\nstrings.replacement(name, replacement)\n```\n\n**Example**\n\n```js\nstrings.replacement('prop', function(match) {\n  return match.toUpperCase();\n});\n```\n\n* `name` {String} \n* `replacement` {String|Function}: The replacement to use when patterns are matched.  \n* `return` {Strings} to allow chaining \n\n\n### .parser\n\nSet a parser that can later be used to parse any given string.\n\n```js\nstrings.parser (name, replacements)\n```\n\n**Example**\n\nPass an object:\n\n```js\nstrings.parser('prop', {\n  pattern: /:([\\\\w]+)/,\n  replacement: function(match) {\n    return match.toUpperCase();\n  }\n);\n```\nOr an array\n\n```js\nstrings.parser('prop', [\n  {\n    pattern: 'a',\n    replacement: 'b'\n  },\n  {\n    pattern: 'c',\n    replacement: 'd'\n  }\n]);\n```\n\n* `name` {String} \n* `arr` {Object|Array}: Object or array of replacement patterns to associate.  \n* `return` {Strings} to allow chaining \n\n\n### .parsers\n\nGet an array of stored parsers by passing a parser name or array of parser names.\n\n```js\nstrings.parsers(array)\n```\n\n**Example**\n\n```js\n// pass an array of parser names\nstrings.parsers(['a', 'b', 'c']);\n\n// or a string\nstrings.parsers('a');\n```\n\n\nUsing `parsers` like this:\n\n```js\nstrings.parsers([\n  'jumbotron',\n  'labels',\n  'progress',\n  'glyphicons',\n  'badges',\n  'alerts',\n  'newlines'\n]);\n```\nis just sugar for:\n\n```js\nvar parsers = [\n  strings.parser('jumbotron'),\n  strings.parser('labels'),\n  strings.parser('progress'),\n  strings.parser('glyphicons'),\n  strings.parser('badges'),\n  strings.parser('alerts'),\n  strings.parser('newlines'),\n];\n```\n\nFor an example, see [markdown-symbols](https://github.com/jonschlinkert/markdown-symbols), which uses this to store replacement patterns for custom markdown symbols.\n\n* `parsers` {String|Array}: string or array of parsers to get.  \n* `return` {Array} \n\n\n### .extendParser\n\nExtend a parser with additional replacement patterns. Useful if you're using\nan external module for replacement patterns and you need to extend it.\n\n```js\nstrings.extendParser(parser, replacements)\n```\n\n**Example**\n\n```js\nstrings.extendParser('prop', {\n  pattern: /:([\\\\w]+)/,\n  replacement: function(str) {\n    return str.toUpperCase();\n  }\n);\n```\n\n* `name` {String}: name of the parser to extend. \n* `arr` {Object|Array}: array of replacement patterns to store with the given name. \n* `pattern` {String|RegExp} \n* `replacement` {String|Function}  \n* `return` {Strings} to allow chaining \n\n\n### .template\n\nSet or get a reusable Strings template, consisting of a propstring\nand an array of parsers.\n\nTemplates are useful since they can be stored and then later used\nwith any context.\n\n```js\nstrings.template(name, propstring, parsers);\n```\n\n**Example**\n\n```js\nstrings.template('abc', ':a/:b/:c', ['a', 'b', 'c']);\n// or use a named propstring\nstrings.template('abc', 'foo', ['a', 'b', 'c']);\n                     here ^\n```\n\n* `name` {String} \n* `propstring` {String} \n* `parsers` {Array}: Names of the parsers to use with the template.  \n* `return` {Strings} to allow chaining \n\n\n### .replace\n\nReplace `:propstrings` with the real values.\n\n```js\nstrings.replace(str, context)\n```\n\n**Example**\n\n```js\nstrings.replace(':a/:b/:c', {\n  a: 'foo',\n  b: 'bar',\n  c: 'baz'\n});\n//=\u003e foo/bar/baz\n```\n\n* `str` {String}: The string with `:propstrings` to replace. \n* `context` {String}: The object with replacement properties.  \n* `return` {Strings} to allow chaining \n\n\n### .process\n\nDirectly process the given prop-string, using a named replacement\npattern or array of named replacement patterns, with the given\ncontext.\n\n```js\nstrings.process(str, parsers, context)\n```\n\n**Examples:**\n\nPass a propstring and the parsers to use:\n\n```js\n// define some parsers to do simple key-value replacements\nstrings.parser('a', {'{foo}': 'AAA'});\nstrings.parser('b', {'{bar}': 'BBB'});\nstrings.parser('c', {'{baz}': 'CCC'});\nconsole.log(strings.process('{foo}/{bar}/{baz}', ['a', 'b', 'c']));\n// =\u003e 'AAA/BBB/CCC'\n```\n\n* `str` {String}: the string to process \n* `parsers` {String|Object|Array}: named parsers or parser objects to use when processing. \n* `context` {Object}: context to use. optional if a global context is passed.  \n* `return` {String} \n\n\n### .run\n\nProcess a template with the given context.\n\n```js\nstrings.run(template, context)\n```\n\n**Example**\n\n```js\nstrings.run('blogTemplate', {\n  dest: '_gh_pages',\n  basename: '2014-07-01-post',\n  ext: '.html'\n});\n```\n\n* `template` {String}: The template to process. \n* `context` {Object}: Optional context object, to bind to replacement function as `this`  \n* `return` {String}\n\n\n## Authors\n \n**Jon Schlinkert**\n \n+ [github/jonschlinkert](https://github.com/jonschlinkert)\n+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) \n \n**Brian Woodward**\n \n+ [github/doowb](https://github.com/doowb)\n+ [twitter/doowb](http://twitter.com/doowb) \n\n\n## License\nCopyright (c) 2014 Brian Woodward, contributors.  \nReleased under the MIT license\n\n***\n\n_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on July 03, 2014._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Fstrings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoowb%2Fstrings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Fstrings/lists"}