Permalink
Browse files

Tag the v0.1.0 release

  • Loading branch information...
0 parents commit 8adba331b01c4d26ba95addfe2c19af5dfd9af91 @mathiasbynens committed Jun 5, 2013
@@ -0,0 +1,2 @@
+# Automatically normalize line endings for all text-based files
+* text=auto
@@ -0,0 +1,17 @@
+# JSON version of coverage report
+coverage/coverage.json
+
+# Installed npm modules
+node_modules
+
+# Folder view configuration files
+.DS_Store
+Desktop.ini
+
+# Thumbnail cache files
+._*
+Thumbs.db
+
+# Files that might appear on external disks
+.Spotlight-V100
+.Trashes
@@ -0,0 +1,6 @@
+.*
+*.md
+coverage
+tests
+bower.json
+Gruntfile.js
@@ -0,0 +1,11 @@
+language: node_js
+node_js:
+ - "0.10"
+ - "0.8"
+env:
+ - TEST_COMMAND="grunt shell:test-node"
+ - TEST_COMMAND="grunt shell:test-phantomjs"
+before_script:
+ - "npm install -g grunt-cli"
+script:
+ $TEST_COMMAND
@@ -0,0 +1,71 @@
+module.exports = function(grunt) {
+
+ grunt.initConfig({
+ 'shell': {
+ 'options': {
+ 'stdout': true,
+ 'stderr': true,
+ 'failOnError': true
+ },
+ 'cover': {
+ 'command': 'istanbul cover --report "html" --verbose --dir "coverage" "tests/tests.js"; istanbul report --root "coverage" --format "html"'
+ },
+ 'test-narwhal': {
+ 'command': 'echo "Testing in Narwhal..."; export NARWHAL_OPTIMIZATION=-1; narwhal "tests/tests.js"'
+ },
+ 'test-phantomjs': {
+ 'command': 'echo "Testing in PhantomJS..."; phantomjs "tests/tests.js"'
+ },
+ // Rhino 1.7R4 has a bug that makes it impossible to test in.
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=775566
+ // To test, use Rhino 1.7R3, or wait (heh) for the 1.7R5 release.
+ 'test-rhino': {
+ 'command': 'echo "Testing in Rhino..."; rhino -opt -1 "tests.js"',
+ 'options': {
+ 'execOptions': {
+ 'cwd': 'tests'
+ }
+ }
+ },
+ 'test-ringo': {
+ 'command': 'echo "Testing in Ringo..."; ringo -o -1 "tests/tests.js"'
+ },
+ 'test-node': {
+ 'command': 'echo "Testing in Node..."; node "tests/tests.js"'
+ },
+ 'test-browser': {
+ 'command': 'echo "Testing in a browser..."; open "tests/index.html"'
+ }
+ },
+ 'template': {
+ 'build': {
+ 'options': {
+ // Generate the regular expressions dynamically using Regenerate
+ 'data': require('./src/data.js')
+ },
+ 'files': {
+ 'string-escape.js': ['src/string-escape.js']
+ }
+ }
+ }
+ });
+
+ grunt.loadNpmTasks('grunt-shell');
+ grunt.loadNpmTasks('grunt-template');
+
+ grunt.registerTask('cover', 'shell:cover');
+ grunt.registerTask('test', [
+ 'shell:test-narwhal',
+ 'shell:test-phantomjs',
+ 'shell:test-rhino',
+ 'shell:test-ringo',
+ 'shell:test-node',
+ 'shell:test-browser'
+ ]);
+
+ grunt.registerTask('default', [
+ 'shell:test-node',
+ 'cover'
+ ]);
+
+};
114 README.md
@@ -0,0 +1,114 @@
+# JavaScript string escape [![Build status](https://travis-ci.org/mathiasbynens/javascript-string-escape.png?branch=master)](https://travis-ci.org/mathiasbynens/javascript-string-escape) [![Dependency status](https://gemnasium.com/mathiasbynens/javascript-string-escape.png)](https://gemnasium.com/mathiasbynens/javascript-string-escape)
+
+This is a JavaScript library for escaping JavaScript strings while generating the shortest possible valid output.
+
+Feel free to fork if you see possible improvements!
+
+## Installation
+
+In a browser:
+
+```html
+<script src="string-escape.js"></script>
+```
+
+Via [npm](http://npmjs.org/):
+
+```bash
+npm install string-escape
+```
+
+In [Narwhal](http://narwhaljs.org/), [Node.js](http://nodejs.org/), and [RingoJS](http://ringojs.org/):
+
+```js
+var stringEscape = require('string-escape');
+```
+
+In [Rhino](http://www.mozilla.org/rhino/):
+
+```js
+load('string-escape.js');
+```
+
+Using an AMD loader like [RequireJS](http://requirejs.org/):
+
+```js
+require(
+ {
+ 'paths': {
+ 'string-escape': 'path/to/string-escape'
+ }
+ },
+ ['string-escape'],
+ function(stringEscape) {
+ console.log(stringEscape);
+ }
+);
+```
+
+## API
+
+### `stringEscape(string, options)`
+
+This function takes a string and returns an escaped version of the string where any characters that are not printable ASCII symbols are escaped using the shortest possible (but valid) [escape sequences for use in JavaScript strings](http://mathiasbynens.be/notes/javascript-escapes).
+
+```js
+stringEscape('Ich ♥ Bücher');
+// → 'Ich \\u2665 B\\xFCcher'
+
+stringEscape('foo 𝌆 bar');
+// → 'foo \\uD834\\uDF06 bar'
+```
+
+The optional `options` argument accepts an object with the following options:
+
+#### `quotes`
+
+The default value for the `quotes` option is `'single'`. This means that any occurences of `'` in the input string will be escaped as `\'`, so that the output can be used in a string literal wrapped in single quotes.
+
+```js
+stringEscape('Lorem ipsum "dolor" sit \'amet\' etc.');
+// → 'Lorem ipsum "dolor" sit \\\'amet\\\' etc.'
+
+stringEscape('Lorem ipsum "dolor" sit \'amet\' etc.', {
+ 'quotes': 'single'
+});
+// → 'Lorem ipsum "dolor" sit \\\'amet\\\' etc.'
+// → "Lorem ipsum \"dolor\" sit \\'amet\\' etc."
+```
+
+If you want to use the output as part of a string literal wrapped in double quotes, set the `quotes` option to `'double'`.
+
+```js
+stringEscape('Lorem ipsum "dolor" sit \'amet\' etc.', {
+ 'quotes': 'double'
+});
+// → 'Lorem ipsum \\"dolor\\" sit \'amet\' etc.'
+// → "Lorem ipsum \\\"dolor\\\" sit 'amet' etc."
+```
+
+### `stringEscape.version`
+
+A string representing the semantic version number.
+
+## Support
+
+This library has been tested in at least Chrome 27-29, Firefox 3-22, Safari 4-6, Opera 10-12, IE 6-10, Node.js v0.10.0, Narwhal 0.3.2, RingoJS 0.8-0.9, PhantomJS 1.9.0, and Rhino 1.7RC4.
+
+## Unit tests & code coverage
+
+After cloning this repository, run `npm install` to install the dependencies needed for development and testing. You may want to install Istanbul _globally_ using `npm install istanbul -g`.
+
+Once that’s done, you can run the unit tests in Node using `npm test` or `node tests/tests.js`. To run the tests in Rhino, Ringo, Narwhal, and web browsers as well, use `grunt test`.
+
+To generate [the code coverage report](http://rawgithub.com/mathiasbynens/javascript-string-escape/master/coverage/string-escape/string-escape.js.html), use `grunt cover`.
+
+## Author
+
+| [![twitter/mathias](http://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](http://twitter.com/mathias "Follow @mathias on Twitter") |
+|---|
+| [Mathias Bynens](http://mathiasbynens.be/) |
+
+## License
+
+This library is dual licensed under the [MIT](http://mths.be/mit) and [GPL](http://mths.be/gpl) licenses.
@@ -0,0 +1,13 @@
+{
+ "name": "javascript-string-escape",
+ "version": "0.1.0",
+ "main": "string-escape.js",
+ "ignore": [
+ "coverage",
+ "tests",
+ ".*",
+ "Gruntfile.js",
+ "package.json",
+ "node_modules"
+ ]
+}
Oops, something went wrong.

0 comments on commit 8adba33

Please sign in to comment.