Permalink
Browse files

Initial commit

  • Loading branch information...
mathiasbynens committed May 5, 2014
0 parents commit 98ff3d60845a8841ae16eb89624cb3350191560d
Showing with 704 additions and 0 deletions.
  1. +2 −0 .gitattributes
  2. +17 −0 .gitignore
  3. +18 −0 .travis.yml
  4. +76 −0 Gruntfile.js
  5. +20 −0 LICENSE-MIT.txt
  6. +113 −0 README.md
  7. +16 −0 bower.json
  8. +21 −0 component.json
  9. +55 −0 package.json
  10. +88 −0 q.js
  11. +30 −0 scripts/export-data.js
  12. +88 −0 src/q.js
  13. +35 −0 tests/index.html
  14. +125 −0 tests/tests.js
@@ -0,0 +1,2 @@
# Automatically normalize line endings for all text-based files
* text=auto
@@ -0,0 +1,17 @@
# Coverage report
coverage

# 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,18 @@
language: node_js
node_js:
- "0.10"
before_script:
- "npm install -g grunt-cli"
# Narwhal uses a hardcoded path to openjdk v6, so use that version
- "sudo apt-get update -qq"
- "sudo apt-get install -qq openjdk-6-jre"
- "PACKAGE=rhino1_7R3; wget http://ftp.mozilla.org/pub/mozilla.org/js/$PACKAGE.zip && sudo unzip $PACKAGE -d /opt/ && rm $PACKAGE.zip"
- "PACKAGE=rhino1_7R3; echo -e '#!/bin/sh\\njava -jar /opt/'$PACKAGE'/js.jar $@' | sudo tee /usr/local/bin/rhino && sudo chmod +x /usr/local/bin/rhino"
- "PACKAGE=ringojs-0.9; wget http://ringojs.org/downloads/$PACKAGE.zip && sudo unzip $PACKAGE -d /opt/ && rm $PACKAGE.zip"
- "PACKAGE=ringojs-0.9; sudo ln -s /opt/$PACKAGE/bin/ringo /usr/local/bin/ringo && sudo chmod +x /usr/local/bin/ringo"
- "PACKAGE=v0.3.2; wget https://github.com/280north/narwhal/archive/$PACKAGE.zip && sudo unzip $PACKAGE -d /opt/ && rm $PACKAGE.zip"
- "PACKAGE=narwhal-0.3.2; sudo ln -s /opt/$PACKAGE/bin/narwhal /usr/local/bin/narwhal && sudo chmod +x /usr/local/bin/narwhal"
# If the enviroment stores rt.jar in a different directory, find it and symlink the directory
- "PREFIX=/usr/lib/jvm; if [ ! -d $PREFIX/java-6-openjdk ]; then for d in $PREFIX/java-6-openjdk-*; do if [ -e $d/jre/lib/rt.jar ]; then sudo ln -s $d $PREFIX/java-6-openjdk; break; fi; done; fi"
script:
"grunt ci"
@@ -0,0 +1,76 @@
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"'
},
'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': {
'data': function() {
return require('./scripts/export-data.js');
}
},
'files': {
'q.js': ['src/q.js']
}
}
}
});

grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-template');

grunt.registerTask('cover', 'shell:cover');
grunt.registerTask('ci', [
'template',
'shell:test-narwhal',
'shell:test-phantomjs',
'shell:test-rhino',
'shell:test-ringo',
'shell:test-node',
]);
grunt.registerTask('test', [
'ci',
'shell:test-browser'
]);

grunt.registerTask('default', [
'template',
'shell:test-node'
]);

};
@@ -0,0 +1,20 @@
Copyright Mathias Bynens <http://mathiasbynens.be/>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
113 README.md
@@ -0,0 +1,113 @@
# q-encoding [![Build status](https://travis-ci.org/mathiasbynens/q-encoding.svg?branch=master)](https://travis-ci.org/mathiasbynens/q-encoding) [![Dependency status](https://gemnasium.com/mathiasbynens/q-encoding.svg)](https://gemnasium.com/mathiasbynens/q-encoding)

_q-encoding_ is a character encoding–agnostic JavaScript implementation of [the `Q` encoding as defined by RFC 2047](http://tools.ietf.org/html/rfc2047#section-4.2). It can be used to encode data with any character encoding to its `Q`-encoded form, or the other way around (i.e. decoding).

## Installation

Via [npm](http://npmjs.org/):

```bash
npm install q-encoding
```

Via [Bower](http://bower.io/):

```bash
bower install q-encoding
```

Via [Component](https://github.com/component/component):

```bash
component install mathiasbynens/q-encoding
```

In a browser:

```html
<script src="q.js"></script>
```

In [Narwhal](http://narwhaljs.org/), [Node.js](http://nodejs.org/), and [RingoJS](http://ringojs.org/):

```js
var q = require('q-encoding');
```

In [Rhino](http://www.mozilla.org/rhino/):

```js
load('q.js');
```

Using an AMD loader like [RequireJS](http://requirejs.org/):

```js
require(
{
'paths': {
'q-encoding': 'path/to/q-encoding'
}
},
['q-encoding'],
function(q) {
console.log(q);
}
);
```

## API

### `q.version`

A string representing the semantic version number.

### `q.encode(input)`

This function takes an encoded string (the `input` parameter) and `Q`-encodes it. Each item in the input string represents an octet as per the desired character encoding. Here’s an example that uses UTF-8:

```js
var utf8 = require('utf8');
q.encode(utf8.encode('foo = bar'));
// → 'foo_=3D_bar'
q.encode(utf8.encode('Iñtërnâtiônàlizætiøn☃💩'));
// → 'I=C3=B1t=C3=ABrn=C3=A2ti=C3=B4n=C3=A0liz=C3=A6ti=C3=B8n=E2=98=83=F0=9F=92=A9'
```

### `q.decode(text, options)`

This function takes a `Q`-encoded string of text (the `text` parameter) and `Q`-decodes it. The return value is a string of which each item represents an octet as per the character encoding that’s being used. Here’s an example that uses UTF-8:

```js
var utf8 = require('utf8');
utf8.decode(q.decode('foo_=3D_bar'));
// → 'foo = bar'
utf8.decode(q.decode('I=C3=B1t=C3=ABrn=C3=A2ti=C3=B4n=C3=A0liz=C3=A6ti=C3=B8n=E2=98=83=F0=9F=92=A9'));
// → 'Iñtërnâtiônàlizætiøn☃💩'
```

## Support

_q-encoding_ is designed to work in at least Node.js v0.10.0, Narwhal 0.3.2, RingoJS 0.8-0.9, PhantomJS 1.9.0, Rhino 1.7RC4, as well as old and modern versions of Chrome, Firefox, Safari, Opera, and Internet Explorer.

## 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, use `grunt cover`.

## Author

| [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") |
|---|
| [Mathias Bynens](http://mathiasbynens.be/) |

## License

_q-encoding_ is available under the [MIT](http://mths.be/mit) license.
@@ -0,0 +1,16 @@
{
"name": "q-encoding",
"version": "0.1.0",
"main": "q.js",
"ignore": [
"bin",
"coverage",
"man",
"tests",
".*",
"component.json",
"Gruntfile.js",
"node_modules",
"package.json"
]
}
@@ -0,0 +1,21 @@
{
"name": "q-encoding",
"version": "0.1.0",
"description": "A robust & character encoding–agnostic JavaScript implementation of the `Q` encoding as defined by RFC 2047.",
"repo": "mathiasbynens/q-encoding",
"license": "MIT",
"scripts": [
"q.js"
],
"main": "q.js",
"keywords": [
"decode",
"decoding",
"encode",
"encoding",
"q-decode",
"q-encode",
"q-encoding",
"string"
]
}
@@ -0,0 +1,55 @@
{
"name": "q-encoding",
"version": "0.1.0",
"description": "A robust & character encoding–agnostic JavaScript implementation of the `Q` encoding as defined by RFC 2047.",
"homepage": "http://mths.be/q",
"main": "q.js",
"keywords": [
"decode",
"decoding",
"encode",
"encoding",
"q-decode",
"q-encode",
"q-encoding",
"string"
],
"licenses": [
{
"type": "MIT",
"url": "http://mths.be/mit"
}
],
"author": {
"name": "Mathias Bynens",
"url": "http://mathiasbynens.be/"
},
"repository": {
"type": "git",
"url": "https://github.com/mathiasbynens/q-encoding.git"
},
"bugs": {
"url": "https://github.com/mathiasbynens/q-encoding/issues"
},
"files": [
"LICENSE-MIT.txt",
"q.js"
],
"directories": {
"test": "tests"
},
"scripts": {
"test": "node tests/tests.js"
},
"devDependencies": {
"grunt": "~0.4.4",
"grunt-shell": "~0.7.0",
"grunt-template": "~0.2.3",
"istanbul": "~0.2.7",
"qunit-extras": "~1.1.0",
"qunitjs": "~1.11.0",
"regenerate": "~0.6.1",
"requirejs": "~2.1.11",
"utf8": "~2.0.0"
}
}
Oops, something went wrong.

0 comments on commit 98ff3d6

Please sign in to comment.