Skip to content

Instantly share code, notes, and snippets.

@MartinTale
Created February 1, 2016 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinTale/4ca0043f3b689fbd898b to your computer and use it in GitHub Desktop.
Save MartinTale/4ca0043f3b689fbd898b to your computer and use it in GitHub Desktop.
/**
* 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(/&#39;/g, '\'')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>');
}
};
{
"name": "test-package",
"version": "1.0.0",
"description": "Test package",
"main": "index.js",
"scripts": {
"dev": "webpack --watch --progress --colors --config webpack.dev.config.js",
"build": "webpack && webpack --config webpack.dev.config.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"babel-core": "^6.4.5",
"babel-eslint": "^4.1.6",
"babel-loader": "^6.2.1",
"babel-preset-es2015": "^6.3.13",
"eslint": "^1.10.3",
"eslint-loader": "^1.2.1",
"webpack": "^1.12.12",
"escope": "3.3.0"
}
}
var webpack = require('webpack');
var uglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
module.exports = {
debug: true,
entry: './index.js',
output: {
path: '.',
filename: "test-package.min.js",
library: "test-package",
libraryTarget: "umd"
},
module: {
preLoaders: [
{
test: /\.js$/,
loader: 'eslint-loader',
exclude: /node_modules/
}
],
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['es2015']
}
}
]
},
plugins: [
new uglifyJsPlugin({
compress: {
warnings: false
}
})
],
eslint: {
configFile: '.eslintrc'
}
};
var webpack = require('webpack');
module.exports = {
debug: true,
entry: './index.js',
output: {
path: '.',
filename: "test-package.js",
library: "test-package",
libraryTarget: "umd"
},
module: {
preLoaders: [
{
test: /\.js$/,
loader: 'eslint-loader',
exclude: /node_modules/
}
],
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['es2015']
}
}
]
},
eslint: {
configFile: '.eslintrc'
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment