snippet.js

Provides utility class for working with text snippets (text snippets can contain tab stops). Additionally extends the String prototype to allow easy conversion to Snippets.

Exports

Snippet (class)

constructor(string)
Single argument; a string that will be used as a snippet.

Returns a Snippet object

var Snippet = require('snippet').Snippet;
var my_snippet = new Snippet('string to be the snippet');
text
String; the textual contents of the snippet
snippet()
Returns CETextSnippet object.
write([overwrite=true, undo_name]))
Returns bool, whether the write was successful or not. If overwrite is false (true by default) the current selection will not be replaced by the snippet. If undo_name is specified it will be used as the action’s undo name (only affects things if overwrite=true).
log()
Void; convenience function for logging the snippet’s text to the console.

New String methods

toSnippet()
Returns Snippet object; converts the string into a snippet.
sanitizedForSnippet()
Returns String; a version of the string with text snippet special characters escaped
log()
Void; convenience function to log the string to the console.

Example

var stuff = 'This is a string';
stuff.toSnippet().write();
Clicky Web Analytics