Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kevva committed Jul 21, 2015
0 parents commit 804b104
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
12 changes: 12 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"bitwise": true,
"curly": true,
"esnext": true,
"immed": true,
"newcap": true,
"noarg": true,
"node": true,
"strict": true,
"undef": true,
"unused": "vars"
}
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- 'iojs'
- '0.12'
- '0.10'
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';
module.exports = function (str) {
if (typeof str !== 'string') {
throw new TypeError('Expected a string');
}

return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
return '%' + c.charCodeAt(0).toString(16);
});
};
21 changes: 21 additions & 0 deletions license
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) Kevin Mårtensson <kevinmartensson@gmail.com> (github.com/kevva)

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.
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "strict-uri-encode",
"version": "0.0.0",
"description": "A stricter URI encode adhering to RFC 3986",
"license": "MIT",
"repository": "kevva/strict-uri-encode",
"author": {
"name": "Kevin Mårtensson",
"email": "kevinmartensson@gmail.com",
"url": "github.com/kevva"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "node test.js"
},
"files": [
"index.js"
],
"keywords": [
"component",
"encode",
"RFC3986",
"uri"
],
"devDependencies": {
"ava": "^0.0.4"
}
}
40 changes: 40 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# strict-uri-encode [![Build Status](https://travis-ci.org/kevva/strict-uri-encode.svg?branch=master)](https://travis-ci.org/kevva/strict-uri-encode)

> A stricter URI encode adhering to [RFC 3986](http://tools.ietf.org/html/rfc3986)

## Install

```
$ npm install --save strict-uri-encode
```


## Usage

```js
var strictUriEncode = require('strict-uri-encode');

strictUriEncode('unicorn*foobar')
//=> 'unicorn%2afoobar'

strictUriEncode('unicorn!foobar')
//=> 'unicorn%21foobar'
```


## API

### strictUriEncode(string)

#### string

*Required*
Type: `string`

String to URI encode.


## License

MIT © [Kevin Mårtensson](http://github.com/kevva)
11 changes: 11 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';
var test = require('ava');
var strictUriEncode = require('./');

test(function (t) {
t.assert(strictUriEncode('unicorn!foobar') === 'unicorn%21foobar');
t.assert(strictUriEncode('unicorn\'foobar') === 'unicorn%27foobar');
t.assert(strictUriEncode('unicorn*foobar') === 'unicorn%2afoobar');
t.assert(strictUriEncode('unicorn*foobar') !== encodeURIComponent('unicorn*foobar'));
t.end();
});

0 comments on commit 804b104

Please sign in to comment.