{"id":13447796,"url":"https://github.com/jonschlinkert/tabstops","last_synced_at":"2025-05-05T15:50:29.020Z","repository":{"id":65513938,"uuid":"198692448","full_name":"jonschlinkert/tabstops","owner":"jonschlinkert","description":"Empower your text editor or prompt with full-featured code snippets! JavaScript library and API for parsing, compiling, and rendering code snippets, with complete support for VS Code-style tabstops. Supports variables, placeholders, transforms, unlimited nesting, and all of the \"snippet\" features offered by popular text editors like VSCode, Atom, TextMate and Sublime Text. ","archived":false,"fork":false,"pushed_at":"2019-08-08T06:39:58.000Z","size":348,"stargazers_count":23,"open_issues_count":1,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-24T13:39:33.294Z","etag":null,"topics":["atom","code","editor","key-bindings","prompt","render","shortcut","snippet","sublime","sublime-text","tab","tabstop","tabstops","template","text-editor","transform","variables","vscode"],"latest_commit_sha":null,"homepage":"https://github.com/jonschlinkert","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/jonschlinkert.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":"2019-07-24T18:49:39.000Z","updated_at":"2024-08-29T23:41:03.000Z","dependencies_parsed_at":"2023-01-26T21:01:21.621Z","dependency_job_id":null,"html_url":"https://github.com/jonschlinkert/tabstops","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Ftabstops","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Ftabstops/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Ftabstops/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Ftabstops/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/tabstops/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252526378,"owners_count":21762487,"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":["atom","code","editor","key-bindings","prompt","render","shortcut","snippet","sublime","sublime-text","tab","tabstop","tabstops","template","text-editor","transform","variables","vscode"],"created_at":"2024-07-31T05:01:27.086Z","updated_at":"2025-05-05T15:50:28.998Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","funding_links":["https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=W8YFZ425KND68"],"categories":["JavaScript"],"sub_categories":[],"readme":"# tabstops [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=W8YFZ425KND68) [![NPM version](https://img.shields.io/npm/v/tabstops.svg?style=flat)](https://www.npmjs.com/package/tabstops) [![NPM monthly downloads](https://img.shields.io/npm/dm/tabstops.svg?style=flat)](https://npmjs.org/package/tabstops) [![NPM total downloads](https://img.shields.io/npm/dt/tabstops.svg?style=flat)](https://npmjs.org/package/tabstops) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/tabstops.svg?style=flat\u0026label=Travis)](https://travis-ci.org/jonschlinkert/tabstops)\n\n\u003e JavaScript library and API for parsing, compiling and rendering snippets with tabstops.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/) (requires [Node.js](https://nodejs.org/en/) \u003e=8):\n\n```sh\n$ npm install --save tabstops\n```\n\n## Features\n\n* [Tabstops](#tabstops) in the following formats: `$1`, `${1}`\n* Tabstops with [placeholders](#placeholders): `${1:foo}`\n* Nested tabstops: `$1 ${2:${1:foo}}`\n* [Variables](#variables) in the following formats: `$name`, `${name}`\n* Variables with placeholders: `${name:Jon Schlinkert}`\n* Nested Variables: `${name:${1}}`, `${name:${fullname:Jon Schlinkert}}`\n* [Choices](#choices): `${1|one,two,three|}`\n* [Variable Transforms](#variable-Transform): `${TM_FILENAME/(.*)\\..+$/$1/gim}`\n* [Placeholder Transforms](#placeholder-Transform): `${1/^_(.*)/$1/g}`\n* more...!\n\n**Supported Formats**\n\n* [TextMate Snippets](https://macromates.com/textmate/manual/snippets)\n* [Atom Snippets](https://flight-manual.atom.io/using-atom/sections/snippets/)\n* [VSCode Snippets](https://code.visualstudio.com/docs/editor/userdefinedsnippets)\n* [Sublime Text Snippets](http://docs.sublimetext.info/en/latest/extensibility/snippets.html)\n\n## Usage\n\nNote that this library _does not load snippets_ from the file system. You need to pass the snippet string.\n\n```js\nconst TabStops = require('tabstops');\n\n// pass a string as the first argument \nconst tabstops = new TabStops('console.log(\"$1\");');\n\nconsole.log(tabstops.render()); //=\u003e 'console.log(\"\");'\n\ntabstops.set(1, 'It worked!');\nconsole.log(tabstops.render()); //=\u003e 'console.log(\"It worked!\");'\n\ntabstops.set(1, 'Warning!');\nconsole.log(tabstops.render()); //=\u003e 'console.log(\"Warning!\");'\n```\n\n## Docs\n\nWIP - user and docs are in progress!!! In the meantime, see the [unit tests](test) for available features and usage examples.\n\n## API\n\nWIP\n\n## Snippet Features\n\nThe following documentation is based on the [VSCode Snippets](https://code.visualstudio.com/docs/editor/userdefinedsnippets) and [TextMate Snippets](https://macromates.com/manual/en/snippets) docs.\n\n### Tabstops\n\nWith tabstops you can make the editor cursor move inside a snippet. Use `$1`, `$2` to specify cursor locations. The number is the order in which tabstops will be visited, whereas `$0` denotes the final cursor position. Multiple tabstops are linked and updated in sync.\n\n### Placeholders\n\nPlaceholders are tabstops with values, like `${1:foo}`. The placeholder text will be inserted and selected such that it can be easily changed. Placeholders can nested, like `${1:another ${2:placeholder}}`.\n\n### Choice\n\nPlaceholders may have choices as values. The syntax is a comma-separated enumeration of values, enclosed with the pipe-character, e.g. `${1|one,two,three|}`. When inserted and selected choices will prompt the user to pick one of the values.\n\n### Variables\n\nWith `$name` or `${name:default}` you can insert the value of a variable. When a variable isn’t set its _default_ or the empty string is inserted. When a variable is unknown (that is, its value is undefined) the name of the variable is inserted instead, and it is transformed into a placeholder.\n\n### Variable-Transform\n\nTransformations allow you to modify the value of a variable before it is being inserted. The definition of a transformation consists of four parts (including the variable to be transformed):\n\n1. The variable to transform\n2. A regular expression that is matched against the value of the variable, or the empty string when the variable cannot be resolved.\n3. A \"format string\" that allows to reference matching groups from the regular expression. The format string allows for conditional inserts and simple modifications.\n4. Options that are passed to the regular expression\n\nThe following sample inserts the name of the current file without its ending, so from `foo.txt` it makes `foo`.\n\n```\n${\u003cvariable\u003e/\u003cregexp\u003e/\u003cformat\u003e/\u003coptions\u003e}\n${TM_FILENAME/(.*)\\..+$/$1/gim}\n  |           |         |  |\n  |           |         |  |-\u003e options (regex flags)\n  |           |         |\n  |           |         |-\u003e references the contents of the first\n  |           |             capture group\n  |           |\n  |           |-\u003e regex to capture everything before\n  |               the final `.suffix`\n  |\n  |-\u003e resolves to the filename\n```\n\n### Placeholder-Transform\n\nLike a Variable-Transform, a transformation of a placeholder allows changing the inserted text for the placeholder when moving to the next tab stop.\n\nThe inserted text is matched with the regular expression and the match or matches - depending on the options - are replaced with the specified replacement format text.\n\nEvery occurrence of a placeholder can define its own transformation independently using the value of the first placeholder.\n\nThe format for Placeholder-Transforms is the same as for Variable-Transforms.\n\nThe following sample removes an underscore at the beginning of the text, so that `_transform` becomes `transform`.\n\n```\n${1/^_(.*)/$1/g}\n  |   |    |  |-\u003e Options (regex flags)\n  |   |    |\n  |   |    |-\u003e Replace it with the first capture group\n  |   |\n  |   |-\u003e Regular expression to capture everything after the underscore\n  |\n  |-\u003e Placeholder Index\n```\n\n### Grammar\n\nBelow is the EBNF for snippets. With `\\` (backslash) you can escape `$`, `}` and `\\`, within choice elements the backslash also escapes comma and pipe characters.\n\n```\nplaceholder ::= tabstop | choice | variable | text\ntabstop     ::= '$' int\n                | '${' int '}'\n                | '${' int1 ':' placeholder '}'\n                | '${' int1 '/' transform '}'\nvariable    ::= '$' var \n                | '${' var '}'\n                | '${' var ':' placeholder '}'\n                | '${' var '/' transform '}'\ntransform   ::= regex '/' (format | text)+ '/' flags\nformat      ::= '$' int  \n                | '${' int '}'\n                | '${' int ':' '/upcase' | '/downcase' | '/capitalize' '}'\n                | '${' int ':+' if '}'\n                | '${' int ':?' if ':' else '}'\n                | '${' int ':-' else '}' \n                | '${' int ':' else '}'\nchoice      ::= '${' int1 '|' text (',' text)* '|}'\nregex       ::= JavaScript Regular Expression value (ctor-string)\nflags       ::= JavaScript Regular Expression flags (ctor-flags)\nvar         ::= [_a-zA-Z][_a-zA-Z0-9]*\nint         ::= [0-9]+\nint1        ::= [1-9]+\ntext        ::= .*\n```\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n\u003c/details\u003e\n\n### Author\n\n**Jon Schlinkert**\n\n* [GitHub Profile](https://github.com/jonschlinkert)\n* [Twitter Profile](https://twitter.com/jonschlinkert)\n* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)\n\n### License\n\nCopyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on July 24, 2019._\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Ftabstops","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Ftabstops","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Ftabstops/lists"}