grunt-jscpd
Version:
Grunt task for use JSCPD lib
52 lines (48 loc) • 1.5 kB
JavaScript
function utf8_encode ( str_data ) {
// Encodes an ISO-8859-1 string to UTF-8
//
// + original by: Webtoolkit.info (http://www.webtoolkit.info/)
str_data = str_data.replace(/\r\n/g,"\n");
var utftext = "";
for (var n = 0; n < str_data.length; n++) {
var c = str_data.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
} else if((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
} else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
}
module.exports = function (store) {
function getset (name, value) {
var node = vars.store;
var keys = name.split('.');
keys.slice(0,-1).forEach(function (k) {
if (node[k] === undefined) node[k] = {};
node = node[k]
});
var key = keys[keys.length - 1];
if (arguments.length == 1) {
return node[key];
}
else {
return node[key] = value;
}
}
var vars = {
get : function (name) {
return getset(name);
},
set : function (name, value) {
return getset(name, value);
},
store : store || {},
};
return vars;
};