Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
first module test
Browse files Browse the repository at this point in the history
  • Loading branch information
chgohlke committed Sep 29, 2016
1 parent 8d54230 commit 2d4825f
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.idea
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test:
./node_modules/.bin/mocha --reporter nyan
.PHONY: test
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# aws-lambda-router
# aws-lambda-router

A small library providing utility methods to `escape` and `unescape` HTML entities

## Tests

npm test

## Release History

* 0.0.1 Initial release
29 changes: 29 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Escape special characters in the given string of html.
*
* @param {String} html
* @return {String}
*/
module.exports = {
escape: function(html) {
return String(html)
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
},

/**
* Unescape special characters in the given string of html.
*
* @param {String} html
* @return {String}
*/
unescape: function(html) {
return String(html)
.replace(/&amp;/g, '&')
.replace(/&quot;/g, '"')
.replace(/&gt;/g, '>');
}
};
28 changes: 28 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "aws-lambda-router",
"version": "0.0.1",
"description": "AWS lambda router",
"main": "index.js",
"scripts": {
"test": "make test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/WeltN24/aws-lambda-router.git"
},
"keywords": [
"aws",
"lambda",
"any"
],
"author": "Christian Gohlke <[email protected]> (https://www.welt.de)",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/WeltN24/aws-lambda-router/issues"
},
"homepage": "https://github.com/WeltN24/aws-lambda-router#readme",
"devDependencies": {
"chai": "^3.5.0",
"mocha": "^3.1.0"
}
}
16 changes: 16 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var should = require('chai').should(),
scapegoat = require('../index'),
escape = scapegoat.escape,
unescape = scapegoat.unescape;

describe('#escape', function() {
it('converts & into &amp;', function() {
escape('&').should.equal('&amp;');
});
});

describe('#unescape', function() {
it('converts &amp; into &', function() {
unescape('&amp;').should.equal('&');
});
});

0 comments on commit 2d4825f

Please sign in to comment.