properties-file
Advanced tools
Comparing version 3.1.1 to 3.2.0
@@ -1,286 +0,74 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PropertiesEditor = exports.DEFAULT_COMMENT_DELIMITER = exports.DEFAULT_SEPARATOR = void 0; | ||
var escape_1 = require("../escape"); | ||
var properties_1 = require("../properties"); | ||
/** The default separator between keys and values. */ | ||
exports.DEFAULT_SEPARATOR = '='; | ||
/** The default character used as comment delimiter. */ | ||
exports.DEFAULT_COMMENT_DELIMITER = '#'; | ||
/** | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PropertiesEditor=exports.DEFAULT_SEPARATOR=exports.DEFAULT_COMMENT_DELIMITER=void 0,require("core-js/modules/es.string.replace.js"),require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/esnext.string.replace-all.js");var _escape=require("../escape"),_properties=require("../properties");/** The default separator between keys and values. */const DEFAULT_SEPARATOR="=";/** The default character used as comment delimiter. */exports.DEFAULT_SEPARATOR="=";const DEFAULT_COMMENT_DELIMITER="#";/** Characters that can be used as key-value pair separators. */ /** Characters that can be used as comment delimiters. */ /** Options on the `Properties.insert` method. */ /** Options on the `Properties.insertComment` method. */ /** Options on the `Properties.update` method. */ /** Options on the `Properties.upsert` method. */exports.DEFAULT_COMMENT_DELIMITER="#";/** | ||
* A .properties file editor. | ||
*/ | ||
var PropertiesEditor = /** @class */ (function (_super) { | ||
__extends(PropertiesEditor, _super); | ||
/** | ||
* Create `PropertiesEditor` object. | ||
* | ||
* @param content - The content of a `.properties` file. | ||
*/ | ||
function PropertiesEditor(content) { | ||
return _super.call(this, content) || this; | ||
} | ||
/** | ||
* Insert a new property in the existing object (by default it will be at the end). | ||
* | ||
* @param key - A property key (unescaped). | ||
* @param value - A property value (unescaped). | ||
* @param options - Additional options. | ||
* | ||
* @returns True if the key was inserted, otherwise false. | ||
*/ | ||
PropertiesEditor.prototype.insert = function (key, value, options) { | ||
var _a; | ||
var _b, _c; | ||
var escapeUnicode = (options === null || options === void 0 ? void 0 : options.escapeUnicode) || false; | ||
var separator = (options === null || options === void 0 ? void 0 : options.separator) | ||
? options.separator === ' ' | ||
? ' ' | ||
: " ".concat(options.separator, " ") | ||
: " ".concat(exports.DEFAULT_SEPARATOR, " ").replace(' ', ' '); | ||
var referenceKey = options === null || options === void 0 ? void 0 : options.referenceKey; | ||
var position = (options === null || options === void 0 ? void 0 : options.position) || 'after'; | ||
// Allow multiline keys. | ||
var multilineKey = key | ||
.split(/\r?\n/) | ||
.map(function (key) { return (0, escape_1.escapeKey)(key, escapeUnicode); }) | ||
.join('\\\n'); | ||
// Allow multiline values. | ||
var multilineValue = value | ||
.split(/\r?\n/) | ||
.map(function (value) { return (0, escape_1.escapeValue)(value, escapeUnicode); }) | ||
.join('\\\n'); | ||
// Allow multiline comments. | ||
var commentPrefix = "".concat((options === null || options === void 0 ? void 0 : options.commentDelimiter) || exports.DEFAULT_COMMENT_DELIMITER, " "); | ||
var multilineComment = (options === null || options === void 0 ? void 0 : options.comment) === undefined | ||
? '' | ||
: "".concat("".concat(commentPrefix).concat(options.comment).split(/\r?\n/).join("\n".concat(commentPrefix)), "\n"); | ||
var newLines = "".concat(multilineComment).concat(multilineKey).concat(separator).concat(multilineValue).split(/\n/); | ||
if (referenceKey === undefined) { | ||
// Insert the new property at the end if the reference key was not defined. | ||
(_a = this.lines).push.apply(_a, __spreadArray([], __read(newLines), false)); | ||
this.parseLines(); | ||
return true; | ||
} | ||
else { | ||
// Find the last occurrence of the reference key. | ||
var property = __spreadArray([], __read(this.collection), false).reverse() | ||
.find(function (property) { return property.key === referenceKey; }); | ||
// Insert the new property when a reference key defined only when found. | ||
if (property) { | ||
var insertPosition = position === 'after' | ||
? property.endingLineNumber | ||
: (_c = (_b = property.previousProperty) === null || _b === void 0 ? void 0 : _b.endingLineNumber) !== null && _c !== void 0 ? _c : 0; | ||
this.lines = __spreadArray(__spreadArray(__spreadArray([], __read(this.lines.slice(0, insertPosition)), false), __read(newLines), false), __read(this.lines.slice(insertPosition)), false); | ||
this.parseLines(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
}; | ||
/** | ||
* Insert a new comment in the existing object (by default it will be at the end). | ||
* | ||
* @param comment - The comment to add. | ||
* @param options - Additional options. | ||
* | ||
* @returns True if the comment was inserted, otherwise false. | ||
*/ | ||
PropertiesEditor.prototype.insertComment = function (comment, options) { | ||
var _a; | ||
var _b, _c; | ||
var referenceKey = options === null || options === void 0 ? void 0 : options.referenceKey; | ||
var position = (options === null || options === void 0 ? void 0 : options.position) || 'after'; | ||
// Allow multiline comments. | ||
var commentPrefix = "".concat((options === null || options === void 0 ? void 0 : options.commentDelimiter) || exports.DEFAULT_COMMENT_DELIMITER, " "); | ||
var newLines = "".concat(commentPrefix).concat(comment) | ||
.replace(/\r?\n/g, "\n".concat(commentPrefix)) | ||
.split(/\n/); | ||
if (referenceKey === undefined) { | ||
// Insert the new comment at the end if the reference key was not defined. | ||
(_a = this.lines).push.apply(_a, __spreadArray([], __read(newLines), false)); | ||
this.parseLines(); | ||
return true; | ||
} | ||
else { | ||
// Find the last occurrence of the reference key. | ||
var property = __spreadArray([], __read(this.collection), false).reverse() | ||
.find(function (property) { return property.key === referenceKey; }); | ||
// Insert the new comment when a reference key defined only when found. | ||
if (property) { | ||
var insertPosition = position === 'after' | ||
? property.endingLineNumber | ||
: (_c = (_b = property.previousProperty) === null || _b === void 0 ? void 0 : _b.endingLineNumber) !== null && _c !== void 0 ? _c : 0; | ||
this.lines = __spreadArray(__spreadArray(__spreadArray([], __read(this.lines.slice(0, insertPosition)), false), __read(newLines), false), __read(this.lines.slice(insertPosition)), false); | ||
this.parseLines(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
}; | ||
/** | ||
* Delete the last occurrence of a given key from the existing object. | ||
* | ||
* @param key - The name of the key to delete. | ||
* @param deleteCommentsAndWhiteSpace - By default, comments and white-space characters before the key will be deleted. | ||
* | ||
* @returns True if the key was deleted, otherwise false. | ||
*/ | ||
PropertiesEditor.prototype.delete = function (key, deleteCommentsAndWhiteSpace) { | ||
var _a, _b; | ||
if (deleteCommentsAndWhiteSpace === void 0) { deleteCommentsAndWhiteSpace = true; } | ||
// Find the last occurrence of the key. | ||
var property = __spreadArray([], __read(this.collection), false).reverse().find(function (property) { return property.key === key; }); | ||
if (property) { | ||
var startLine = deleteCommentsAndWhiteSpace | ||
? (_b = (_a = property.previousProperty) === null || _a === void 0 ? void 0 : _a.endingLineNumber) !== null && _b !== void 0 ? _b : 0 | ||
: property.startingLineNumber - 1; | ||
var endLine = property.endingLineNumber; | ||
this.lines = __spreadArray(__spreadArray([], __read(this.lines.slice(0, startLine)), false), __read(this.lines.slice(endLine)), false); | ||
this.parseLines(); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
/** | ||
* Restore the original newline characters of a key. | ||
* | ||
* @param property - A property object. | ||
* | ||
* @returns The key with its original newlines characters restored. | ||
*/ | ||
PropertiesEditor.prototype.getKeyWithNewlines = function (property) { | ||
return property.newlinePositions.length === 0 | ||
? property.key | ||
: // eslint-disable-next-line unicorn/no-array-reduce | ||
__spreadArray([], __read(property.key), false).reduce(function (accumulator, character, index) { | ||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions | ||
return "".concat(accumulator).concat(property.newlinePositions.includes(index) ? '\n' : '').concat(character); | ||
}, ''); | ||
}; | ||
/** | ||
* Restore the original newline characters of a value. | ||
* | ||
* @param property - A property object. | ||
* | ||
* @returns The value with its original newlines characters restored. | ||
*/ | ||
PropertiesEditor.prototype.getValueWithNewlines = function (property) { | ||
return property.newlinePositions.length === 0 || property.valuePosition === undefined | ||
? property.value | ||
: // eslint-disable-next-line unicorn/no-array-reduce | ||
__spreadArray([], __read(property.value), false).reduce(function (accumulator, character, index) { | ||
return "".concat(accumulator).concat(property.newlinePositions.includes(index + property.valuePosition) | ||
? '\n' | ||
: '' | ||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions | ||
).concat(character); | ||
}, ''); | ||
}; | ||
/** | ||
* Update the last occurrence of a given key from the existing object. | ||
* | ||
* @param key - The name of the key to update. | ||
* @param options - Additional options. | ||
* | ||
* @returns True if the key was updated, otherwise false. | ||
*/ | ||
PropertiesEditor.prototype.update = function (key, options) { | ||
var _a, _b, _c, _d; | ||
// Find the last occurrence of the key to update. | ||
var property = __spreadArray([], __read(this.collection), false).reverse().find(function (property) { return property.key === key; }); | ||
if (!property || !options) { | ||
return false; | ||
} | ||
var escapeUnicode = options.escapeUnicode || false; | ||
var separator = options.separator | ||
? options.separator === ' ' | ||
? ' ' | ||
: " ".concat(options.separator, " ") | ||
: property.separator || " ".concat(exports.DEFAULT_SEPARATOR, " ").replace(' ', ' '); | ||
// Allow multiline keys. | ||
var multilineKey = ((_a = options.newKey) !== null && _a !== void 0 ? _a : this.getKeyWithNewlines(property)) | ||
.split(/\r?\n/) | ||
.map(function (key) { return (0, escape_1.escapeKey)(key, escapeUnicode); }) | ||
.join('\\\n'); | ||
// Allow multiline values. | ||
var multilineValue = ((_b = options.newValue) !== null && _b !== void 0 ? _b : this.getValueWithNewlines(property)) | ||
.split(/\r?\n/) | ||
.map(function (value) { return (0, escape_1.escapeValue)(value, escapeUnicode); }) | ||
.join('\\\n'); | ||
// Allow multiline comments. | ||
var commentPrefix = "".concat(options.commentDelimiter || exports.DEFAULT_COMMENT_DELIMITER, " "); | ||
var multilineComment = options.newComment === undefined | ||
? '' | ||
: "".concat("".concat(commentPrefix).concat(options.newComment).split(/\r?\n/).join("\n".concat(commentPrefix)), "\n"); | ||
var newLines = "".concat(multilineComment).concat(multilineKey).concat(separator).concat(multilineValue).split(/\n/); | ||
// Replace the existing property with the new one. | ||
this.lines = __spreadArray(__spreadArray(__spreadArray([], __read(this.lines.slice(0, options.newComment === undefined | ||
? property.startingLineNumber - 1 | ||
: (_d = (_c = property.previousProperty) === null || _c === void 0 ? void 0 : _c.endingLineNumber) !== null && _d !== void 0 ? _d : 0)), false), __read(newLines), false), __read(this.lines.slice(property.endingLineNumber)), false); | ||
this.parseLines(); | ||
return true; | ||
}; | ||
/** | ||
* Update a key if it exist, otherwise add it at the end. | ||
* | ||
* @param key - A property key (unescaped). | ||
* @param value - A property value (unescaped). | ||
* @param options - Additional options. | ||
* | ||
* @returns True if the key was updated or inserted, otherwise false. | ||
*/ | ||
PropertiesEditor.prototype.upsert = function (key, value, options) { | ||
return this.keyLineNumbers[key] | ||
? this.update(key, { | ||
newValue: value, | ||
newComment: options === null || options === void 0 ? void 0 : options.comment, | ||
commentDelimiter: options === null || options === void 0 ? void 0 : options.commentDelimiter, | ||
separator: options === null || options === void 0 ? void 0 : options.separator, | ||
escapeUnicode: options === null || options === void 0 ? void 0 : options.escapeUnicode, | ||
}) | ||
: this.insert(key, value, options); | ||
}; | ||
return PropertiesEditor; | ||
}(properties_1.Properties)); | ||
exports.PropertiesEditor = PropertiesEditor; | ||
*/class PropertiesEditor extends _properties.Properties{/** | ||
* Create `PropertiesEditor` object. | ||
* | ||
* @param content - The content of a `.properties` file. | ||
*/constructor(a){super(a)}/** | ||
* Insert a new property in the existing object (by default it will be at the end). | ||
* | ||
* @param key - A property key (unescaped). | ||
* @param value - A property value (unescaped). | ||
* @param options - Additional options. | ||
* | ||
* @returns True if the key was inserted, otherwise false. | ||
*/insert(a,b,c){const d=(null===c||void 0===c?void 0:c.escapeUnicode)||!1,e=null!==c&&void 0!==c&&c.separator?" "===c.separator?" ":" ".concat(c.separator," "):" ".concat(DEFAULT_SEPARATOR," ").replace(" "," "),f=null===c||void 0===c?void 0:c.referenceKey,g=(null===c||void 0===c?void 0:c.position)||"after",h=a.split(/\r?\n/).map(a=>(0,_escape.escapeKey)(a,d)).join("\\\n"),i=b.split(/\r?\n/).map(a=>(0,_escape.escapeValue)(a,d)).join("\\\n"),j="".concat((null===c||void 0===c?void 0:c.commentDelimiter)||DEFAULT_COMMENT_DELIMITER," "),k=(null===c||void 0===c?void 0:c.comment)===void 0?"":"".concat("".concat(j).concat(c.comment).split(/\r?\n/).join("\n".concat(j)),"\n"),l="".concat(k).concat(h).concat(e).concat(i).split(/\n/);// Allow multiline keys. | ||
// Allow multiline values. | ||
// Allow multiline comments. | ||
if(void 0===f)return this.lines.push(...l),this.parseLines(),!0;else{// Find the last occurrence of the reference key. | ||
const a=[...this.collection].reverse().find(a=>a.key===f);// Insert the new property when a reference key defined only when found. | ||
if(a){var m,n;const b="after"===g?a.endingLineNumber:null!==(m=null===(n=a.previousProperty)||void 0===n?void 0:n.endingLineNumber)&&void 0!==m?m:0;return this.lines=[...this.lines.slice(0,b),...l,...this.lines.slice(b)],this.parseLines(),!0}return!1}}/** | ||
* Insert a new comment in the existing object (by default it will be at the end). | ||
* | ||
* @param comment - The comment to add. | ||
* @param options - Additional options. | ||
* | ||
* @returns True if the comment was inserted, otherwise false. | ||
*/insertComment(a,b){const c=null===b||void 0===b?void 0:b.referenceKey,d=(null===b||void 0===b?void 0:b.position)||"after",e="".concat((null===b||void 0===b?void 0:b.commentDelimiter)||DEFAULT_COMMENT_DELIMITER," "),f="".concat(e).concat(a).replaceAll(/\r?\n/g,"\n".concat(e)).split(/\n/);// Allow multiline comments. | ||
if(void 0===c)return this.lines.push(...f),this.parseLines(),!0;else{// Find the last occurrence of the reference key. | ||
const a=[...this.collection].reverse().find(a=>a.key===c);// Insert the new comment when a reference key defined only when found. | ||
if(a){var g,h;const b="after"===d?a.endingLineNumber:null!==(g=null===(h=a.previousProperty)||void 0===h?void 0:h.endingLineNumber)&&void 0!==g?g:0;return this.lines=[...this.lines.slice(0,b),...f,...this.lines.slice(b)],this.parseLines(),!0}return!1}}/** | ||
* Delete the last occurrence of a given key from the existing object. | ||
* | ||
* @param key - The name of the key to delete. | ||
* @param deleteCommentsAndWhiteSpace - By default, comments and white-space characters before the key will be deleted. | ||
* | ||
* @returns True if the key was deleted, otherwise false. | ||
*/delete(a){let b=!(1<arguments.length&&arguments[1]!==void 0)||arguments[1];// Find the last occurrence of the key. | ||
const c=[...this.collection].reverse().find(b=>b.key===a);if(c){var d,e;const a=b?null!==(d=null===(e=c.previousProperty)||void 0===e?void 0:e.endingLineNumber)&&void 0!==d?d:0:c.startingLineNumber-1,f=c.endingLineNumber;return this.lines=[...this.lines.slice(0,a),...this.lines.slice(f)],this.parseLines(),!0}return!1}/** | ||
* Restore the original newline characters of a key. | ||
* | ||
* @param property - A property object. | ||
* | ||
* @returns The key with its original newlines characters restored. | ||
*/getKeyWithNewlines(a){return 0===a.newlinePositions.length?a.key:// eslint-disable-next-line unicorn/no-array-reduce | ||
[...a.key].reduce((b,c,d)=>// eslint-disable-next-line @typescript-eslint/restrict-template-expressions | ||
"".concat(b).concat(a.newlinePositions.includes(d)?"\n":"").concat(c),"")}/** | ||
* Restore the original newline characters of a value. | ||
* | ||
* @param property - A property object. | ||
* | ||
* @returns The value with its original newlines characters restored. | ||
*/getValueWithNewlines(a){return 0===a.newlinePositions.length||a.valuePosition===void 0?a.value:// eslint-disable-next-line unicorn/no-array-reduce | ||
[...a.value].reduce((b,c,d)=>"".concat(b).concat(a.newlinePositions.includes(d+a.valuePosition)?"\n":""// eslint-disable-next-line @typescript-eslint/restrict-template-expressions | ||
).concat(c),"")}/** | ||
* Update the last occurrence of a given key from the existing object. | ||
* | ||
* @param key - The name of the key to update. | ||
* @param options - Additional options. | ||
* | ||
* @returns True if the key was updated, otherwise false. | ||
*/update(a,b){var c,d,e,f;// Find the last occurrence of the key to update. | ||
const g=[...this.collection].reverse().find(b=>b.key===a);if(!g||!b)return!1;const h=b.escapeUnicode||!1,i=b.separator?" "===b.separator?" ":" ".concat(b.separator," "):g.separator||" ".concat(DEFAULT_SEPARATOR," ").replace(" "," "),j=(null!==(c=b.newKey)&&void 0!==c?c:this.getKeyWithNewlines(g)).split(/\r?\n/).map(a=>(0,_escape.escapeKey)(a,h)).join("\\\n"),k=(null!==(d=b.newValue)&&void 0!==d?d:this.getValueWithNewlines(g)).split(/\r?\n/).map(a=>(0,_escape.escapeValue)(a,h)).join("\\\n"),l="".concat(b.commentDelimiter||DEFAULT_COMMENT_DELIMITER," "),m=void 0===b.newComment?"":"".concat("".concat(l).concat(b.newComment).split(/\r?\n/).join("\n".concat(l)),"\n"),n="".concat(m).concat(j).concat(i).concat(k).split(/\n/);// Allow multiline keys. | ||
// Allow multiline values. | ||
// Allow multiline comments. | ||
// Replace the existing property with the new one. | ||
return this.lines=[...this.lines.slice(0,void 0===b.newComment?g.startingLineNumber-1:null!==(e=null===(f=g.previousProperty)||void 0===f?void 0:f.endingLineNumber)&&void 0!==e?e:0),...n,...this.lines.slice(g.endingLineNumber)],this.parseLines(),!0}/** | ||
* Update a key if it exist, otherwise add it at the end. | ||
* | ||
* @param key - A property key (unescaped). | ||
* @param value - A property value (unescaped). | ||
* @param options - Additional options. | ||
* | ||
* @returns True if the key was updated or inserted, otherwise false. | ||
*/upsert(a,b,c){return this.keyLineNumbers[a]?this.update(a,{newValue:b,newComment:null===c||void 0===c?void 0:c.comment,commentDelimiter:null===c||void 0===c?void 0:c.commentDelimiter,separator:null===c||void 0===c?void 0:c.separator,escapeUnicode:null===c||void 0===c?void 0:c.escapeUnicode}):this.insert(a,b,c)}}exports.PropertiesEditor=PropertiesEditor; |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.escapeValue = exports.escapeKey = void 0; | ||
/** | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.escapeValue=exports.escapeKey=void 0;/** | ||
* Escape a property key. | ||
@@ -11,9 +8,3 @@ * | ||
* @return The escaped key. | ||
*/ | ||
var escapeKey = function (unescapedKey, escapeUnicode) { | ||
if (escapeUnicode === void 0) { escapeUnicode = false; } | ||
return escapeContent(unescapedKey, true, escapeUnicode); | ||
}; | ||
exports.escapeKey = escapeKey; | ||
/** | ||
*/const escapeKey=function(a){let b=!!(1<arguments.length&&arguments[1]!==void 0)&&arguments[1];return escapeContent(a,!0,b)};/** | ||
* Escape property value. | ||
@@ -25,9 +16,3 @@ * | ||
* @return The escaped value. | ||
*/ | ||
var escapeValue = function (unescapedValue, escapeUnicode) { | ||
if (escapeUnicode === void 0) { escapeUnicode = false; } | ||
return escapeContent(unescapedValue, false, escapeUnicode); | ||
}; | ||
exports.escapeValue = escapeValue; | ||
/** | ||
*/exports.escapeKey=escapeKey;const escapeValue=function(a){let b=!!(1<arguments.length&&arguments[1]!==void 0)&&arguments[1];return escapeContent(a,!1,b)};/** | ||
* Escape the content from either key or value of a property. | ||
@@ -40,60 +25,5 @@ * | ||
* @returns The unescaped content. | ||
*/ | ||
var escapeContent = function (unescapedContent, escapeSpace, escapeUnicode) { | ||
var escapedContent = ''; | ||
for (var character = unescapedContent[0], position = 0; position < unescapedContent.length; position++, character = unescapedContent[position]) { | ||
switch (character) { | ||
case ' ': { | ||
// Escape space if required, or if it is first character. | ||
escapedContent += escapeSpace || position === 0 ? '\\ ' : ' '; | ||
break; | ||
} | ||
// Backslash. | ||
case '\\': { | ||
escapedContent += '\\\\'; | ||
break; | ||
} | ||
case '\f': { | ||
// Formfeed. | ||
escapedContent += '\\f'; | ||
break; | ||
} | ||
case '\n': { | ||
// Newline. | ||
escapedContent += '\\n'; | ||
break; | ||
} | ||
case '\r': { | ||
// Carriage return. | ||
escapedContent += '\\r'; | ||
break; | ||
} | ||
case '\t': { | ||
// Tab. | ||
escapedContent += '\\t'; | ||
break; | ||
} | ||
case '=': | ||
case ':': | ||
case '#': | ||
case '!': { | ||
// Escapes =, :, # and !. | ||
escapedContent += "\\".concat(character); | ||
break; | ||
} | ||
default: { | ||
if (escapeUnicode) { | ||
var codePoint = character.codePointAt(0); // Can never be `undefined`. | ||
if (codePoint < 0x0020 || codePoint > 0x007e) { | ||
escapedContent += "\\u".concat(codePoint.toString(16).padStart(4, '0')); | ||
break; | ||
} | ||
} | ||
// Non-escapable characters. | ||
escapedContent += character; | ||
break; | ||
} | ||
} | ||
} | ||
return escapedContent; | ||
}; | ||
*/exports.escapeValue=escapeValue;const escapeContent=(a,b,c)=>{let d="";for(let e=a[0],f=0;f<a.length;f++,e=a[f])switch(e){case" ":{d+=b||0===f?"\\ ":" ";break}// Backslash. | ||
case"\\":{d+="\\\\";break}case"\f":{d+="\\f";break}case"\n":{d+="\\n";break}case"\r":{d+="\\r";break}case"\t":{d+="\\t";break}case"=":case":":case"#":case"!":{d+="\\".concat(e);break}default:{if(c){const a=e.codePointAt(0);// Can never be `undefined`. | ||
if(32>a||126<a){d+="\\u".concat(a.toString(16).padStart(4,"0"));break}}// Non-escapable characters. | ||
d+=e;break}}return d}; |
/// <reference types="./properties-file" /> | ||
/// <reference types="node" /> | ||
@@ -4,0 +3,0 @@ export { Properties } from './properties'; |
@@ -1,8 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getProperties = exports.Properties = void 0; | ||
var properties_1 = require("./properties"); | ||
var properties_2 = require("./properties"); | ||
Object.defineProperty(exports, "Properties", { enumerable: true, get: function () { return properties_2.Properties; } }); | ||
/** | ||
"use strict";var _properties=require("./properties");Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"Properties",{enumerable:!0,get:function(){return _properties.Properties}}),exports.getProperties=void 0;/** | ||
* A key-value pair object. | ||
*/ /** | ||
* Converts the content of a `.properties` file to a key-value pair object. | ||
@@ -13,6 +9,2 @@ * | ||
* @returns A key/value object representing the content of a `.properties` file. | ||
*/ | ||
var getProperties = function (content) { | ||
return new properties_1.Properties(content).toObject(); | ||
}; | ||
exports.getProperties = getProperties; | ||
*/const getProperties=a=>new _properties.Properties(a).toObject();exports.getProperties=getProperties; |
/// <reference types="../properties-file" /> | ||
/** | ||
@@ -4,0 +3,0 @@ * Webpack file loader for `.properties` files. |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var __1 = require(".."); | ||
/** | ||
"use strict";var _=require("..");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;/** | ||
* Webpack file loader for `.properties` files. | ||
@@ -10,6 +7,2 @@ * | ||
* @returns A Webpack file loader string containing the content of a `.properties` file. | ||
*/ | ||
var webpackLoader = function (content) { | ||
return "module.exports = ".concat(JSON.stringify((0, __1.getProperties)(content)), ";"); | ||
}; | ||
exports.default = webpackLoader; | ||
*/const webpackLoader=a=>"module.exports = ".concat(JSON.stringify((0,_.getProperties)(a)),";");var _default=webpackLoader;exports.default=_default; |
@@ -94,3 +94,3 @@ /// <reference types="node" /> | ||
*/ | ||
getApplicableLineNumber(): number; | ||
getApplicableLineNumber(): number | undefined; | ||
} |
@@ -1,41 +0,4 @@ | ||
"use strict"; | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.KeyCollisions = exports.Properties = exports.getFirstEolCharacter = exports.DEFAULT_END_OF_LINE_CHARACTER = exports.BOM_CODE_POINT = exports.BOM = void 0; | ||
var property_1 = require("./property"); | ||
var property_line_1 = require("./property-line"); | ||
/** | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getFirstEolCharacter=exports.Properties=exports.KeyCollisions=exports.DEFAULT_END_OF_LINE_CHARACTER=exports.BOM_CODE_POINT=exports.BOM=void 0,require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/esnext.string.at.js");var _property=require("./property"),_propertyLine=require("./property-line");function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}/** | ||
* Byte-order mark. | ||
*/ | ||
exports.BOM = '\uFEFF'; | ||
exports.BOM_CODE_POINT = exports.BOM.codePointAt(0); | ||
/** The default end of line character. */ | ||
exports.DEFAULT_END_OF_LINE_CHARACTER = '\n'; | ||
/** | ||
*/const BOM="\uFEFF";exports.BOM="\uFEFF";const BOM_CODE_POINT="\uFEFF".codePointAt(0);/** The default end of line character. */exports.BOM_CODE_POINT=65279;const DEFAULT_END_OF_LINE_CHARACTER="\n";/** | ||
* Get the first end of line (EOL) character from multiline content. | ||
@@ -46,174 +9,45 @@ * | ||
* @returns The multiline content's first end of line (EOL) character. | ||
*/ | ||
var getFirstEolCharacter = function (content) { | ||
var newlineIndex = content.indexOf('\n'); | ||
return newlineIndex < 0 ? undefined : "".concat(content[newlineIndex - 1] === '\r' ? '\r' : '', "\n"); | ||
}; | ||
exports.getFirstEolCharacter = getFirstEolCharacter; | ||
/** | ||
*/exports.DEFAULT_END_OF_LINE_CHARACTER="\n";const getFirstEolCharacter=a=>{const b=a.indexOf("\n");return 0>b?void 0:"".concat("\r"===a[b-1]?"\r":"","\n")};/** | ||
* A class representing the content of a .properties file. | ||
*/ | ||
var Properties = /** @class */ (function () { | ||
/** | ||
* Create `Properties` object. | ||
* | ||
* @param content - The content of a `.properties` file. | ||
*/ | ||
function Properties(content) { | ||
var _a; | ||
/** The collection of property object. */ | ||
this.collection = []; | ||
/** Object associating keys with their starting line numbers. */ | ||
this.keyLineNumbers = {}; | ||
var stringContent = typeof content === 'string' ? content : content.toString(); | ||
this.hasBom = stringContent.codePointAt(0) === exports.BOM_CODE_POINT; | ||
this.eolCharacter = (_a = (0, exports.getFirstEolCharacter)(stringContent)) !== null && _a !== void 0 ? _a : exports.DEFAULT_END_OF_LINE_CHARACTER; | ||
this.lines = (this.hasBom ? stringContent.slice(1) : stringContent).split(/\r?\n/); | ||
this.parseLines(); | ||
} | ||
/** | ||
* Parse the `.properties` content line by line. | ||
*/ | ||
Properties.prototype.parseLines = function () { | ||
var e_1, _a; | ||
/** reset existing object properties to their initial values. */ | ||
this.collection = []; | ||
this.keyLineNumbers = {}; | ||
/** Line number while parsing properties file content. */ | ||
var lineNumber = 0; | ||
/** The current property object being parsed. */ | ||
var property; | ||
/** The previous property object that was parsed. */ | ||
var previousProperty; | ||
try { | ||
for (var _b = __values(this.lines), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var line = _c.value; | ||
lineNumber++; | ||
var propertyLine = new property_line_1.PropertyLine(line, !!property); | ||
if (property) { | ||
// Continue parsing an existing property. | ||
property.addLine(propertyLine); | ||
if (propertyLine.isContinuing) { | ||
continue; | ||
} | ||
} | ||
else { | ||
// Check if the line is a new property. | ||
if (propertyLine.isComment || propertyLine.isBlank) { | ||
continue; // Skip line if its a comment or blank. | ||
} | ||
// The line is a new property. | ||
property = new property_1.Property(propertyLine, lineNumber, previousProperty); | ||
if (propertyLine.isContinuing) { | ||
continue; // Continue parsing the next line. | ||
} | ||
} | ||
// If the line does not continue, add the property to the collection. | ||
this.addToCollection(property); | ||
previousProperty = property; | ||
property = undefined; | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
}; | ||
/** | ||
* Add a property object into a properties object collection. | ||
* | ||
* @param property - A property object, or undefined. | ||
* | ||
* @returns Undefined so that we conveniently overwrite the property object. | ||
*/ | ||
Properties.prototype.addToCollection = function (property) { | ||
var _a; | ||
property.setKeyAndValue(); | ||
if ((_a = this.keyLineNumbers[property.key]) === null || _a === void 0 ? void 0 : _a.length) { | ||
this.keyLineNumbers[property.key].push(property.startingLineNumber); | ||
property.hasKeyCollisions = true; | ||
property.keyCollisionLines = this.keyLineNumbers[property.key]; | ||
// Remove the collision from the collection (we only keep latest value). | ||
this.collection = this.collection.filter(function (existingPropertyObject) { return existingPropertyObject.key !== property.key; }); | ||
} | ||
else { | ||
// Initialize the key line numbers. | ||
this.keyLineNumbers[property.key] = [property.startingLineNumber]; | ||
} | ||
// Add the property to the collection. | ||
this.collection.push(property); | ||
}; | ||
/** | ||
* Get keys that have collisions (more than one occurrence). | ||
*/ | ||
Properties.prototype.getKeyCollisions = function () { | ||
var e_2, _a; | ||
var keyCollisions = []; | ||
try { | ||
for (var _b = __values(Object.entries(this.keyLineNumbers)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var _d = __read(_c.value, 2), key = _d[0], startingLineNumbers = _d[1]; | ||
if (startingLineNumbers.length > 1) { | ||
keyCollisions.push(new KeyCollisions(key, startingLineNumbers)); | ||
} | ||
} | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
return keyCollisions; | ||
}; | ||
/** | ||
* Get the key/value object representing the properties. | ||
* | ||
* @returns A key/value object representing the properties. | ||
*/ | ||
Properties.prototype.toObject = function () { | ||
var keyValueObject = {}; | ||
this.collection.forEach(function (property) { | ||
keyValueObject[property.key] = property.value; | ||
}); | ||
return keyValueObject; | ||
}; | ||
/** | ||
* Format the object in `.properties`. | ||
* | ||
* @param endOfLineCharacter - The character used for end of lines. | ||
* | ||
* @returns The object in `.properties` format. | ||
*/ | ||
Properties.prototype.format = function (endOfLineCharacter) { | ||
return "".concat(this.hasBom ? exports.BOM : '').concat(this.lines.join(endOfLineCharacter || this.eolCharacter)); | ||
}; | ||
return Properties; | ||
}()); | ||
exports.Properties = Properties; | ||
/** | ||
*/exports.getFirstEolCharacter=getFirstEolCharacter;class Properties{/** | ||
* Create `Properties` object. | ||
* | ||
* @param content - The content of a `.properties` file. | ||
*/constructor(a){var b;_defineProperty(this,"collection",[]),_defineProperty(this,"keyLineNumbers",{});const c="string"==typeof a?a:a.toString();this.hasBom=c.codePointAt(0)===BOM_CODE_POINT,this.eolCharacter=null!==(b=getFirstEolCharacter(c))&&void 0!==b?b:DEFAULT_END_OF_LINE_CHARACTER,this.lines=(this.hasBom?c.slice(1):c).split(/\r?\n/),this.parseLines()}/** | ||
* Parse the `.properties` content line by line. | ||
*/parseLines(){this.collection=[],this.keyLineNumbers={};/** Line number while parsing properties file content. */let a,b,c=0;/** The current property object being parsed. */ /** The previous property object that was parsed. */for(const d of this.lines){c++;const e=new _propertyLine.PropertyLine(d,!!a);if(!a){// Check if the line is a new property. | ||
if(e.isComment||e.isBlank)continue;// Skip line if its a comment or blank. | ||
// The line is a new property. | ||
if(a=new _property.Property(e,c,b),e.isContinuing)continue;// Continue parsing the next line. | ||
}else if(a.addLine(e),e.isContinuing)continue;// If the line does not continue, add the property to the collection. | ||
this.addToCollection(a),b=a,a=void 0}}/** | ||
* Add a property object into a properties object collection. | ||
* | ||
* @param property - A property object, or undefined. | ||
* | ||
* @returns Undefined so that we conveniently overwrite the property object. | ||
*/addToCollection(a){var b;// Add the property to the collection. | ||
a.setKeyAndValue(),null!==(b=this.keyLineNumbers[a.key])&&void 0!==b&&b.length?(this.keyLineNumbers[a.key].push(a.startingLineNumber),a.hasKeyCollisions=!0,a.keyCollisionLines=this.keyLineNumbers[a.key],this.collection=this.collection.filter(b=>b.key!==a.key)):this.keyLineNumbers[a.key]=[a.startingLineNumber],this.collection.push(a)}/** | ||
* Get keys that have collisions (more than one occurrence). | ||
*/getKeyCollisions(){const a=[];for(const[b,c]of Object.entries(this.keyLineNumbers))1<c.length&&a.push(new KeyCollisions(b,c));return a}/** | ||
* Get the key/value object representing the properties. | ||
* | ||
* @returns A key/value object representing the properties. | ||
*/toObject(){const a={};return this.collection.forEach(b=>{a[b.key]=b.value}),a}/** | ||
* Format the object in `.properties`. | ||
* | ||
* @param endOfLineCharacter - The character used for end of lines. | ||
* | ||
* @returns The object in `.properties` format. | ||
*/format(a){return"".concat(this.hasBom?BOM:"").concat(this.lines.join(a||this.eolCharacter))}}/** | ||
* Object associating keys with their line numbers. | ||
*/exports.Properties=Properties;/** | ||
* A class representing key within a .properties file that had collisions (more than one occurrence). | ||
*/ | ||
var KeyCollisions = /** @class */ (function () { | ||
/** | ||
* Create a new key collision object. | ||
* | ||
* @param key - The key with collisions. | ||
* @param startingLineNumbers - The starting line numbers where collisions are found. | ||
*/ | ||
function KeyCollisions(key, startingLineNumbers) { | ||
this.key = key; | ||
this.startingLineNumbers = startingLineNumbers; | ||
} | ||
/** | ||
* Get the number of the line from which the value will be used. | ||
*/ | ||
KeyCollisions.prototype.getApplicableLineNumber = function () { | ||
return this.startingLineNumbers.slice(-1)[0]; | ||
}; | ||
return KeyCollisions; | ||
}()); | ||
exports.KeyCollisions = KeyCollisions; | ||
*/class KeyCollisions{/** The key with collisions. */ /** The starting line numbers where collisions are found. */ /** | ||
* Create a new key collision object. | ||
* | ||
* @param key - The key with collisions. | ||
* @param startingLineNumbers - The starting line numbers where collisions are found. | ||
*/constructor(a,b){this.key=a,this.startingLineNumbers=b}/** | ||
* Get the number of the line from which the value will be used. | ||
*/getApplicableLineNumber(){return this.startingLineNumbers.at(-1)}}exports.KeyCollisions=KeyCollisions; |
@@ -1,48 +0,9 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PropertyLine = void 0; | ||
/** | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PropertyLine=void 0;function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}/** | ||
* Object representing a line from the content of .properties file. | ||
*/ | ||
var PropertyLine = /** @class */ (function () { | ||
/** | ||
* Create a new line object. | ||
* | ||
* @param line - The raw content of a line. | ||
* @param isMultiline - Is the line spreading on multiple lines? | ||
*/ | ||
function PropertyLine(line, isMultiline) { | ||
/** True if the line is continuing to the next line, otherwise false. */ | ||
this.isContinuing = false; | ||
/** True if the line is blank, otherwise false. */ | ||
this.isBlank = false; | ||
/** True if the line is a comment, otherwise false. */ | ||
this.isComment = false; | ||
this.content = line.trimStart(); | ||
this.isMultiline = isMultiline; | ||
if (this.content.length === 0) { | ||
// Line is blank. | ||
this.isBlank = true; | ||
} | ||
else { | ||
if (!this.isMultiline) { | ||
// Line is a comment. | ||
this.isComment = !!/^[!#]/.test(this.content); | ||
} | ||
if (!this.isComment) { | ||
// Otherwise, check if the line is continuing on the next line. | ||
var backslashMatch = this.content.match(/(?<backslashes>\\+)$/); | ||
if (backslashMatch === null || backslashMatch === void 0 ? void 0 : backslashMatch.groups) { | ||
// If the number of backslashes is odd, the line is continuing, otherwise it doesn't. | ||
this.isContinuing = !!(backslashMatch.groups.backslashes.length % 2); | ||
if (this.isContinuing) { | ||
// Remove the trailing slash so that we can concatenate the line with the next one. | ||
this.content = this.content.slice(0, -1); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return PropertyLine; | ||
}()); | ||
exports.PropertyLine = PropertyLine; | ||
*/class PropertyLine{/** Is the line object a continuation from a previous line? */ /** | ||
* Create a new line object. | ||
* | ||
* @param line - The raw content of a line. | ||
* @param isMultiline - Is the line spreading on multiple lines? | ||
*/constructor(a,b){if(_defineProperty(this,"isContinuing",!1),_defineProperty(this,"isBlank",!1),_defineProperty(this,"isComment",!1),this.content=a.trimStart(),this.isMultiline=b,0===this.content.length)this.isBlank=!0;else if(this.isMultiline||(this.isComment=!!/^[!#]/.test(this.content)),!this.isComment){// Otherwise, check if the line is continuing on the next line. | ||
const a=this.content.match(/(?<backslashes>\\+)$/);null!==a&&void 0!==a&&a.groups&&(this.isContinuing=!!(a.groups.backslashes.length%2),this.isContinuing&&(this.content=this.content.slice(0,-1)))}}}exports.PropertyLine=PropertyLine; |
@@ -1,171 +0,38 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Property = void 0; | ||
var unescape_1 = require("./unescape"); | ||
/** | ||
"use strict";var _unescape=require("./unescape");Object.defineProperty(exports,"__esModule",{value:!0}),exports.Property=void 0;function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}/** | ||
* Object representing a property (key/value). | ||
*/ | ||
var Property = /** @class */ (function () { | ||
/** | ||
* Create a new property object. | ||
* | ||
* @param propertyLine - A property line object. | ||
* @param startingLineNumber - The line number at which the property starts. | ||
*/ | ||
function Property(propertyLine, startingLineNumber, previousProperty) { | ||
/** The property key (unescaped). */ | ||
this.key = ''; | ||
/** The property key, including its escaped characters. */ | ||
this.escapedKey = ''; | ||
/** Is the key empty? */ | ||
this.hasNoKey = false; | ||
/** Does the key definition spread across multiple lines? */ | ||
this.hasMultilineKey = false; | ||
/** Starting line numbers of property objects with the same key. */ | ||
this.keyCollisionLines = []; | ||
/** Was the property's key used more than once? */ | ||
this.hasKeyCollisions = false; | ||
/** The property value (unescaped). */ | ||
this.value = ''; | ||
/** The property value, including its escaped characters. */ | ||
this.escapedValue = ''; | ||
/** Is the value empty? */ | ||
this.hasNoValue = false; | ||
/** Positions of the newline characters if any. */ | ||
this.newlinePositions = []; | ||
this.linesContent = propertyLine.content; | ||
this.startingLineNumber = startingLineNumber; | ||
this.endingLineNumber = startingLineNumber; | ||
this.previousProperty = previousProperty; | ||
previousProperty === null || previousProperty === void 0 ? void 0 : previousProperty.setNextProperty(this); | ||
} | ||
/** | ||
* Set the next property object. | ||
* | ||
* @param property - The next property object | ||
*/ | ||
Property.prototype.setNextProperty = function (property) { | ||
this.nextProperty = property; | ||
}; | ||
/** | ||
* Add the a line to a multiline property object. | ||
* | ||
* @param propertyLine - A property line object. | ||
*/ | ||
Property.prototype.addLine = function (propertyLine) { | ||
if (this.linesContent.length > 0) { | ||
this.newlinePositions.push(this.linesContent.length); | ||
this.endingLineNumber++; | ||
} | ||
this.linesContent += propertyLine.content; | ||
}; | ||
/** | ||
* Set the property's key and value. | ||
*/ | ||
Property.prototype.setKeyAndValue = function () { | ||
this.findSeparator(); | ||
if (this.separatorPosition !== undefined && this.separatorLength !== undefined) { | ||
// Set key if present. | ||
if (!this.hasNoKey) { | ||
this.escapedKey = this.linesContent.slice(0, this.separatorPosition); | ||
this.key = this.unescapeLine(this.escapedKey, this.startingLineNumber); | ||
} | ||
// Set value if present. | ||
if (!this.hasNoValue) { | ||
this.escapedValue = this.linesContent.slice(this.separatorPosition + this.separatorLength); | ||
this.value = this.unescapeLine(this.escapedValue, this.startingLineNumber); | ||
} | ||
} | ||
else if (this.hasNoValue) { | ||
// Set key if present (no separator). | ||
this.escapedKey = this.linesContent; | ||
this.key = this.unescapeLine(this.escapedKey, this.startingLineNumber); | ||
} | ||
}; | ||
/** | ||
* Unescape the content from either key or value of a property. | ||
* | ||
* @param escapedContent - The content to unescape. | ||
* @param startingLineNumber - The starting line number of the content being unescaped. | ||
* | ||
* @returns The unescaped content. | ||
* | ||
* @throws {@link Error} | ||
* This exception is thrown if malformed escaped unicode characters are present. | ||
*/ | ||
Property.prototype.unescapeLine = function (escapedContent, startingLineNumber) { | ||
try { | ||
return (0, unescape_1.unescapeContent)(escapedContent); | ||
} | ||
catch (error) { | ||
throw new Error("".concat(error.message, " in property starting at line ").concat(startingLineNumber)); | ||
} | ||
}; | ||
/** | ||
* Find the character separating the key from the value. | ||
*/ | ||
Property.prototype.findSeparator = function () { | ||
var _a, _b; | ||
// If the separator was already found, skip. | ||
if (this.hasNoKey || this.hasNoValue || this.separatorPosition) { | ||
return; | ||
} | ||
for (var character = this.linesContent[0], position = 0; position < this.linesContent.length; position++, character = this.linesContent[position]) { | ||
// If the character is not a separator, check the next one. | ||
if (!/[\t\f :=]/.test(character)) { | ||
continue; | ||
} | ||
// Check if the separator might be escaped. | ||
var prefix = position ? this.linesContent.slice(0, position) : ''; | ||
if (prefix.length > 0) { | ||
var backslashMatch = prefix.match(/(?<backslashes>\\+)$/); | ||
if (backslashMatch === null || backslashMatch === void 0 ? void 0 : backslashMatch.groups) { | ||
var separatorIsEscaped = !!(backslashMatch.groups.backslashes.length % 2); | ||
if (separatorIsEscaped) { | ||
// If the separator is escaped, check the next character. | ||
continue; | ||
} | ||
} | ||
} | ||
var separator = ''; | ||
this.separatorPosition = position; | ||
// Check if the separator starts with a whitespace. | ||
var nextContent = this.linesContent.slice(position); | ||
var leadingWhitespaceMatch = nextContent.match(/^(?<whitespace>\s+)/); | ||
var leadingWhitespace = ((_a = leadingWhitespaceMatch === null || leadingWhitespaceMatch === void 0 ? void 0 : leadingWhitespaceMatch.groups) === null || _a === void 0 ? void 0 : _a.whitespace) || ''; | ||
// If there is a whitespace, move to the next character. | ||
if (leadingWhitespace.length > 0) { | ||
separator += leadingWhitespace; | ||
nextContent = nextContent.slice(leadingWhitespace.length); | ||
} | ||
// Check if there is an equal or colon character. | ||
if (/[:=]/.test(nextContent[0])) { | ||
separator += nextContent[0]; | ||
nextContent = nextContent.slice(1); | ||
// If an equal or colon character was found, try to get trailing whitespace. | ||
var trailingWhitespaceMatch = nextContent.match(/^(?<whitespace>\s+)/); | ||
var trailingWhitespace = ((_b = trailingWhitespaceMatch === null || trailingWhitespaceMatch === void 0 ? void 0 : trailingWhitespaceMatch.groups) === null || _b === void 0 ? void 0 : _b.whitespace) || ''; | ||
separator += trailingWhitespace; | ||
} | ||
this.separatorLength = separator.length; | ||
this.valuePosition = this.separatorPosition + this.separatorLength; | ||
this.separator = this.linesContent.slice(this.separatorPosition, this.separatorPosition + this.separatorLength); | ||
// If the line starts with a separator, the property has no key. | ||
if (!position) { | ||
this.hasNoKey = true; | ||
} | ||
break; | ||
} | ||
if (this.separatorPosition === undefined) { | ||
// If there was no separator found, the property has no value. | ||
this.hasNoValue = true; | ||
} | ||
else if (this.newlinePositions.length > 0 && | ||
this.newlinePositions[0] < this.separatorPosition) { | ||
// If the separator is after the first newline, the key is on multiple lines. | ||
this.hasMultilineKey = true; | ||
} | ||
}; | ||
return Property; | ||
}()); | ||
exports.Property = Property; | ||
*/class Property{/** The line number at which the property starts. */ /** The line number at which the property ends. */ /** The previous property object if it exists. */ /** The next property object if it exists. */ /** | ||
* Create a new property object. | ||
* | ||
* @param propertyLine - A property line object. | ||
* @param startingLineNumber - The line number at which the property starts. | ||
*/constructor(a,b,c){/** The content of one or multiple lines when applicable. */ /** The property key (unescaped). */ /** The property key, including its escaped characters. */ /** Is the key empty? */ /** Does the key definition spread across multiple lines? */ /** Starting line numbers of property objects with the same key. */ /** Was the property's key used more than once? */ /** The property value (unescaped). */ /** The property value, including its escaped characters. */ /** Is the value empty? */ /** Positions of the newline characters if any. */_defineProperty(this,"key",""),_defineProperty(this,"escapedKey",""),_defineProperty(this,"hasNoKey",!1),_defineProperty(this,"hasMultilineKey",!1),_defineProperty(this,"keyCollisionLines",[]),_defineProperty(this,"hasKeyCollisions",!1),_defineProperty(this,"value",""),_defineProperty(this,"escapedValue",""),_defineProperty(this,"hasNoValue",!1),_defineProperty(this,"newlinePositions",[]),this.linesContent=a.content,this.startingLineNumber=b,this.endingLineNumber=b,this.previousProperty=c,null===c||void 0===c?void 0:c.setNextProperty(this)}/** | ||
* Set the next property object. | ||
* | ||
* @param property - The next property object | ||
*/setNextProperty(a){this.nextProperty=a}/** | ||
* Add the a line to a multiline property object. | ||
* | ||
* @param propertyLine - A property line object. | ||
*/addLine(a){0<this.linesContent.length&&(this.newlinePositions.push(this.linesContent.length),this.endingLineNumber++),this.linesContent+=a.content}/** | ||
* Set the property's key and value. | ||
*/setKeyAndValue(){this.findSeparator(),this.separatorPosition!==void 0&&this.separatorLength!==void 0?(!this.hasNoKey&&(this.escapedKey=this.linesContent.slice(0,this.separatorPosition),this.key=this.unescapeLine(this.escapedKey,this.startingLineNumber)),!this.hasNoValue&&(this.escapedValue=this.linesContent.slice(this.separatorPosition+this.separatorLength),this.value=this.unescapeLine(this.escapedValue,this.startingLineNumber))):this.hasNoValue&&(this.escapedKey=this.linesContent,this.key=this.unescapeLine(this.escapedKey,this.startingLineNumber))}/** | ||
* Unescape the content from either key or value of a property. | ||
* | ||
* @param escapedContent - The content to unescape. | ||
* @param startingLineNumber - The starting line number of the content being unescaped. | ||
* | ||
* @returns The unescaped content. | ||
* | ||
* @throws {@link Error} | ||
* This exception is thrown if malformed escaped unicode characters are present. | ||
*/unescapeLine(a,b){try{return(0,_unescape.unescapeContent)(a)}catch(a){throw new Error("".concat(a.message," in property starting at line ").concat(b))}}/** | ||
* Find the character separating the key from the value. | ||
*/findSeparator(){// If the separator was already found, skip. | ||
if(!(this.hasNoKey||this.hasNoValue||this.separatorPosition)){for(let c=this.linesContent[0],d=0;d<this.linesContent.length;d++,c=this.linesContent[d]){var a;// If the character is not a separator, check the next one. | ||
if(!/[\t\f :=]/.test(c))continue;// Check if the separator might be escaped. | ||
const e=d?this.linesContent.slice(0,d):"";if(0<e.length){const a=e.match(/(?<backslashes>\\+)$/);if(null!==a&&void 0!==a&&a.groups){const b=!!(a.groups.backslashes.length%2);if(b)// If the separator is escaped, check the next character. | ||
continue}}let f="";this.separatorPosition=d;// Check if the separator starts with a whitespace. | ||
let g=this.linesContent.slice(d);const h=g.match(/^(?<whitespace>\s+)/),i=(null===h||void 0===h||null===(a=h.groups)||void 0===a?void 0:a.whitespace)||"";// If there is a whitespace, move to the next character. | ||
// Check if there is an equal or colon character. | ||
if(0<i.length&&(f+=i,g=g.slice(i.length)),/[:=]/.test(g[0])){var b;f+=g[0],g=g.slice(1);// If an equal or colon character was found, try to get trailing whitespace. | ||
const a=g.match(/^(?<whitespace>\s+)/),c=(null===a||void 0===a||null===(b=a.groups)||void 0===b?void 0:b.whitespace)||"";f+=c}this.separatorLength=f.length,this.valuePosition=this.separatorPosition+this.separatorLength,this.separator=this.linesContent.slice(this.separatorPosition,this.separatorPosition+this.separatorLength),d||(this.hasNoKey=!0);break}void 0===this.separatorPosition?this.hasNoValue=!0:0<this.newlinePositions.length&&this.newlinePositions[0]<this.separatorPosition&&(this.hasMultilineKey=!0)}}}exports.Property=Property; |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.unescapeContent = void 0; | ||
/** | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.unescapeContent=void 0;/** | ||
* Unescape the content from either key or value of a property. | ||
@@ -13,58 +10,5 @@ * | ||
* This exception is thrown if malformed escaped unicode characters are present. | ||
*/ | ||
var unescapeContent = function (escapedContent) { | ||
var unescapedContent = ''; | ||
for (var character = escapedContent[0], position = 0; position < escapedContent.length; position++, character = escapedContent[position]) { | ||
if (character === '\\') { | ||
var nextCharacter = escapedContent[position + 1]; | ||
switch (nextCharacter) { | ||
case 'f': { | ||
// Formfeed. | ||
unescapedContent += '\f'; | ||
position++; | ||
break; | ||
} | ||
case 'n': { | ||
// Newline. | ||
unescapedContent += '\n'; | ||
position++; | ||
break; | ||
} | ||
case 'r': { | ||
// Carriage return. | ||
unescapedContent += '\r'; | ||
position++; | ||
break; | ||
} | ||
case 't': { | ||
// Tab. | ||
unescapedContent += '\t'; | ||
position++; | ||
break; | ||
} | ||
case 'u': { | ||
// Unicode character. | ||
var codePoint = escapedContent.slice(position + 2, position + 6); | ||
if (!/[\da-f]{4}/i.test(codePoint)) { | ||
// Code point can only be within Unicode's Multilingual Plane (BMP). | ||
throw new Error("malformed escaped unicode characters '\\u".concat(codePoint, "'")); | ||
} | ||
unescapedContent += String.fromCodePoint(Number.parseInt(codePoint, 16)); | ||
position += 5; | ||
break; | ||
} | ||
default: { | ||
// Otherwise the escape character is not required. | ||
unescapedContent += nextCharacter; | ||
position++; | ||
} | ||
} | ||
} | ||
else { | ||
// When there is \, simply add the character. | ||
unescapedContent += character; | ||
} | ||
} | ||
return unescapedContent; | ||
}; | ||
exports.unescapeContent = unescapeContent; | ||
*/const unescapeContent=a=>{let b="";for(let c=a[0],d=0;d<a.length;d++,c=a[d])if("\\"===c){const c=a[d+1];switch(c){case"f":{b+="\f",d++;break}case"n":{b+="\n",d++;break}case"r":{b+="\r",d++;break}case"t":{b+="\t",d++;break}case"u":{// Unicode character. | ||
const c=a.slice(d+2,d+6);if(!/[\da-f]{4}/i.test(c))// Code point can only be within Unicode's Multilingual Plane (BMP). | ||
throw new Error("malformed escaped unicode characters '\\u".concat(c,"'"));b+=String.fromCodePoint(Number.parseInt(c,16)),d+=5;break}default:b+=c,d++}}else// When there is \, simply add the character. | ||
b+=c;return b};exports.unescapeContent=unescapeContent; |
{ | ||
"name": "properties-file", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"description": ".properties file parser, editor, formatter and Webpack loader.", | ||
@@ -56,3 +56,3 @@ "keywords": [ | ||
"add-import-type": "ts-node ./src/add-import-type.ts && rm -f ./lib/add-import-type.*", | ||
"build": "npm run prettier && npm run lint-fix && rm -Rf ./lib && tsc && npm run add-import-type && npm run test", | ||
"build": "npm run prettier && npm run lint-fix && rm -Rf ./lib && babel --config-file ./.babelrc --extensions .ts src -d lib && tsc && npm run add-import-type && npm run test", | ||
"ci": "npm run build", | ||
@@ -67,8 +67,13 @@ "lint-check": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx --ext .json .", | ||
"devDependencies": { | ||
"@babel/cli": "^7.21.5", | ||
"@babel/core": "^7.21.8", | ||
"@babel/preset-env": "^7.21.5", | ||
"@babel/preset-typescript": "^7.21.5", | ||
"@release-it/conventional-changelog": "5.1.1", | ||
"@types/jest": "29.5.1", | ||
"@typescript-eslint/eslint-plugin": "5.59.1", | ||
"@typescript-eslint/parser": "5.59.1", | ||
"@typescript-eslint/eslint-plugin": "5.59.2", | ||
"@typescript-eslint/parser": "5.59.2", | ||
"babel-preset-minify": "^0.5.2", | ||
"dotenv-cli": "7.2.1", | ||
"eslint": "8.39.0", | ||
"eslint": "8.40.0", | ||
"eslint-config-prettier": "8.8.0", | ||
@@ -79,7 +84,7 @@ "eslint-import-resolver-node": "0.3.7", | ||
"eslint-plugin-jest": "27.2.1", | ||
"eslint-plugin-json-files": "2.1.0", | ||
"eslint-plugin-json-files": "2.2.0", | ||
"eslint-plugin-prefer-arrow-functions": "3.1.4", | ||
"eslint-plugin-prettier": "4.2.1", | ||
"eslint-plugin-tsdoc": "0.2.17", | ||
"eslint-plugin-unicorn": "46.0.0", | ||
"eslint-plugin-unicorn": "47.0.0", | ||
"jest": "29.5.0", | ||
@@ -89,3 +94,3 @@ "prettier": "2.8.8", | ||
"prettier-plugin-sh": "0.12.8", | ||
"release-it": "15.10.2", | ||
"release-it": "15.10.3", | ||
"ts-jest": "29.1.0", | ||
@@ -92,0 +97,0 @@ "ts-node": "10.9.1", |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances 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
53525
29
641
3