properties
Advanced tools
Comparing version 0.1.7 to 0.1.8
{ | ||
"name": "properties", | ||
"version": "0.1.7", | ||
"description": "Provides a simple persistence way to store and retrieve key-value properties.", | ||
"version": "0.1.8", | ||
"description": "A Java .properties file parser ported to node.js.", | ||
"keywords": ["properties", "persistence", "parser"], | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -1,1 +0,1 @@ | ||
"use strict";var BufferedReader=require("buffered-reader"),BufferedWriter=require("buffered-writer"),unicodeStringToCharacter=function(a){var b=0,c;for(var d=0;d<4;d++){c=a[d];switch(c){case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":b=(b<<4)+c.charCodeAt(0)-48;break;case"a":case"b":case"c":case"d":case"e":case"f":b=(b<<4)+c.charCodeAt(0)-88;break;case"A":case"B":case"C":case"D":case"E":case"F":b=(b<<4)+c.charCodeAt(0)-55}}return String.fromCharCode(b)},characterToUnicodeString=function(a){var b=a.charCodeAt(0);return"\\u"+toHex(b>>12)+toHex(b>>8)+toHex(b>>4)+toHex(b)},toHex=function(a){var b="0123456789ABCDEF";return b[a&15]},PropertyReader=function(a,b){this._onLine=a,this._onEOF=b,this._skipWhiteSpace=!0,this._isCommentLine=!1,this._isNewLine=!0,this._appendedLineBegin=!1,this._precedingBackslash=!1,this._skipLF=!1,this._line=""};PropertyReader.prototype._convert=function(a,b,c){var d,e="",f;while(a<b)d=c[a++],d==="\\"?(d=c[a++],d==="u"?e+=unicodeStringToCharacter(c[a++]+c[a++]+c[a++]+c[a++]):(d==="t"?d=" ":d==="r"?d="\r":d==="n"?d="\n":d==="f"&&(d="\f"),e+=d)):e+=d;return e},PropertyReader.prototype._readKeyValue=function(a){var b=!1,c=!1,d=a.length,e=d,f=0,g;while(f<d){g=a[f];if((g==="="||g===":")&&!c){e=f+1,b=!0;break}if((g===" "||g===" "||g=="\f")&&!c){e=f+1;break}g==="\\"?c=!c:c=!1,f++}while(e<d){g=a[e];if(g!==" "&&g!==" "&&g!=="\f"){if(!!b||g!=="="&&g!==":")break;b=!0}e++}this._onLine(this._convert(0,f,a),this._convert(e,d,a))},PropertyReader.prototype.eof=function(){this._line&&this._readKeyValue(this._line),this._onEOF()},PropertyReader.prototype.parse=function(a){if(this._isCommentLine){if(a==="\r"||a==="\n")this._isCommentLine=!1,this._isNewLine=!0,this._skipWhiteSpace=!0;return}if(this._skipLF){this._skipLF=!1;if(a==="\n")return}if(this._skipWhiteSpace){if(a===" "||a===" "||a==="\f")return;if(!this._appendedLineBegin&&(a==="\r"||a==="\n"))return;this._skipWhiteSpace=!1,this._appendedLineBegin=!1}if(this._isNewLine){this._isNewLine=!1;if(a==="#"||a==="!"){this._isCommentLine=!0;return}}a!=="\n"&&a!=="\r"?(this._line+=a,a==="\\"?this._precedingBackslash=!this._precedingBackslash:this._precedingBackslash=!1):this._precedingBackslash?(this._line=this._line.substring(0,this._line.length-1),this._skipWhiteSpace=!0,this._appendedLineBegin=!0,this._precedingBackslash=!1,a==="\r"&&(this._skipLF=!0)):(this._isNewLine=!0,this._skipWhiteSpace=!0,this._line&&this._readKeyValue(this._line),this._line="")};var Properties=function(){this._keys={}};Properties.SEPARATOR="=",Properties.COMMENT="#",Properties.prototype.get=function(a,b){var c=this._keys[a];return c!==undefined?c.value:b},Properties.prototype.keys=function(){return Object.keys(this._keys)},Properties.prototype.load=function(a,b){b&&(b=b.bind(this));var c=this,d=new PropertyReader(function(a,b){c._keys[a]={value:b}},function(){b&&b(null,!0)});(new BufferedReader(a,{encoding:"utf8"})).on("error",function(a){b&&b(a,!1)}).on("character",function(a){d.parse(a)}).on("end",function(){d.eof()}).read()},Properties.prototype.set=function(a,b,c){return this._keys[a]={value:b?b.toString():b,comment:c},this};var convert=function(a,b,c){var d,e,f="";if(!a)return f;for(var g=0,h=a.length;g<h;g++){d=a[g],e=d.charCodeAt(0);if(e>61&&e<127){d==="\\"?(f+="\\",f+="\\"):f+=d;continue}switch(d){case" ":if(g===0||b)f+="\\";f+=" ";break;case" ":f+="\\",f+="t";break;case"\n":f+="\\",f+="n";break;case"\r":f+="\\",f+="r";break;case"\f":f+="\\",f+="f";break;case"=":case":":case"#":case"!":f+="\\",f+=d;break;default:e<33||e>126?f+=c?characterToUnicodeString(d):d:f+=d}}return f};Properties.prototype.store=function(a,b,c,d){var e=arguments.length,f;e===1?b=!1:e===2?(f=typeof b,f==="function"?(d=b,b=!1,c=null):f==="string"&&(c=b,b=!1)):e===3&&(f=typeof b,f==="boolean"&&typeof c=="function"?(d=c,c=null):f==="string"&&(d=c,c=b,b=!1)),d&&(d=d.bind(this));var g=new BufferedWriter(a,{encoding:"utf8"});g.on("error",function(a){d&&d(a,!1)}),c&&g.write(Properties.COMMENT+c).newLine();var h;for(var i in this._keys)h=this._keys[i],h.comment&&g.write(Properties.COMMENT+h.comment).newLine(),g.write(convert(i,!0,b)+Properties.SEPARATOR+convert(h.value,!1,b)).newLine();g.close(),d&&d(null,!0)},module.exports=Properties; | ||
"use strict";var BufferedReader=require("buffered-reader"),BufferedWriter=require("buffered-writer"),unicodeStringToCharacter=function(e){var t=0,n;for(var r=0;r<4;r++){n=e[r];switch(n){case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":t=(t<<4)+n.charCodeAt(0)-48;break;case"a":case"b":case"c":case"d":case"e":case"f":t=(t<<4)+n.charCodeAt(0)-88;break;case"A":case"B":case"C":case"D":case"E":case"F":t=(t<<4)+n.charCodeAt(0)-55}}return String.fromCharCode(t)},characterToUnicodeString=function(e){var t=e.charCodeAt(0);return"\\u"+toHex(t>>12)+toHex(t>>8)+toHex(t>>4)+toHex(t)},toHex=function(e){var t="0123456789ABCDEF";return t[e&15]},PropertyReader=function(e,t){this._onLine=e,this._onEOF=t,this._skipWhiteSpace=!0,this._isCommentLine=!1,this._isNewLine=!0,this._appendedLineBegin=!1,this._precedingBackslash=!1,this._skipLF=!1,this._line=""};PropertyReader.prototype._convert=function(e,t,n){var r,i="",s;while(e<t)r=n[e++],r==="\\"?(r=n[e++],r==="u"?i+=unicodeStringToCharacter(n[e++]+n[e++]+n[e++]+n[e++]):(r==="t"?r=" ":r==="r"?r="\r":r==="n"?r="\n":r==="f"&&(r="\f"),i+=r)):i+=r;return i},PropertyReader.prototype._readKeyValue=function(e){var t=!1,n=!1,r=e.length,i=r,s=0,o;while(s<r){o=e[s];if((o==="="||o===":")&&!n){i=s+1,t=!0;break}if((o===" "||o===" "||o=="\f")&&!n){i=s+1;break}o==="\\"?n=!n:n=!1,s++}while(i<r){o=e[i];if(o!==" "&&o!==" "&&o!=="\f"){if(!!t||o!=="="&&o!==":")break;t=!0}i++}this._onLine(this._convert(0,s,e),this._convert(i,r,e))},PropertyReader.prototype.eof=function(){this._line&&this._readKeyValue(this._line),this._onEOF()},PropertyReader.prototype.parse=function(e){if(this._isCommentLine){if(e==="\r"||e==="\n")this._isCommentLine=!1,this._isNewLine=!0,this._skipWhiteSpace=!0;return}if(this._skipLF){this._skipLF=!1;if(e==="\n")return}if(this._skipWhiteSpace){if(e===" "||e===" "||e==="\f")return;if(!this._appendedLineBegin&&(e==="\r"||e==="\n"))return;this._skipWhiteSpace=!1,this._appendedLineBegin=!1}if(this._isNewLine){this._isNewLine=!1;if(e==="#"||e==="!"){this._isCommentLine=!0;return}}e!=="\n"&&e!=="\r"?(this._line+=e,e==="\\"?this._precedingBackslash=!this._precedingBackslash:this._precedingBackslash=!1):this._precedingBackslash?(this._line=this._line.substring(0,this._line.length-1),this._skipWhiteSpace=!0,this._appendedLineBegin=!0,this._precedingBackslash=!1,e==="\r"&&(this._skipLF=!0)):(this._isNewLine=!0,this._skipWhiteSpace=!0,this._line&&this._readKeyValue(this._line),this._line="")};var Properties=function(){this._keys={}};Properties.COMMENT="#",Properties.SENSITIVITY=!0,Properties.SEPARATOR="=",Properties.prototype.get=function(e,t){var n=this._keys[e];return n!==undefined?n.value:t},Properties.prototype.keys=function(){return Object.keys(this._keys)},Properties.prototype.load=function(e,t){t&&(t=t.bind(this));var n=this,r=new PropertyReader(function(e,t){if(!Properties.SENSITIVITY){var r=e.toLowerCase();for(var i in n._keys)if(r===i.toLowerCase())return}n._keys[e]={value:t}},function(){t&&t(null)});(new BufferedReader(e,{encoding:"utf8"})).on("error",function(e){t&&t(e)}).on("character",function(e){r.parse(e)}).on("end",function(){r.eof()}).read()},Properties.prototype.set=function(e,t,n){if(!Properties.SENSITIVITY){var r=e.toLowerCase();for(var i in this._keys)if(r===i.toLowerCase())return this}return this._keys[e]={value:t?t.toString():t,comment:n},this};var convert=function(e,t,n){var r,i,s="";if(!e)return s;for(var o=0,u=e.length;o<u;o++){r=e[o],i=r.charCodeAt(0);if(i>61&&i<127){r==="\\"?(s+="\\",s+="\\"):s+=r;continue}switch(r){case" ":if(o===0||t)s+="\\";s+=" ";break;case" ":s+="\\",s+="t";break;case"\n":s+="\\",s+="n";break;case"\r":s+="\\",s+="r";break;case"\f":s+="\\",s+="f";break;case"=":case":":case"#":case"!":s+="\\",s+=r;break;default:i<33||i>126?s+=n?characterToUnicodeString(r):r:s+=r}}return s};Properties.prototype.store=function(e,t,n,r){var i=arguments.length,s;i===1?t=!1:i===2?(s=typeof t,s==="function"?(r=t,t=!1,n=null):s==="string"&&(n=t,t=!1)):i===3&&(s=typeof t,s==="boolean"&&typeof n=="function"?(r=n,n=null):s==="string"&&(r=n,n=t,t=!1)),r&&(r=r.bind(this));var o=new BufferedWriter(e,{encoding:"utf8"});o.on("error",function(e){r&&r(e)}),n&&o.write(Properties.COMMENT+n).newLine();var u;for(var a in this._keys)u=this._keys[a],u.comment&&o.write(Properties.COMMENT+u.comment).newLine(),o.write(convert(a,!0,t)+Properties.SEPARATOR+convert(u.value,!1,t)).newLine();o.close(function(){r&&r(null)})},module.exports=Properties; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5037
1