Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

properties-file

Package Overview
Dependencies
Maintainers
1
Versions
110
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

properties-file - npm Package Compare versions

Comparing version 2.0.9 to 2.1.0

2

lib/content/index.js

@@ -16,3 +16,3 @@ "use strict";

// Remove BOM character if present and create an array from lines.
var lines = (content.charCodeAt(0) === 0xfeff ? content.slice(1) : content).split(/\r?\n/);
var lines = (content.codePointAt(0) === 0xfeff ? content.slice(1) : content).split(/\r?\n/);
/** Line number while parsing properties file content. */

@@ -19,0 +19,0 @@ var lineNumber = 0;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.propertiesToJson = exports.getProperties = void 0;
var fs_1 = require("fs");
var node_fs_1 = require("node:fs");
var content_1 = require("../content/");

@@ -15,6 +15,6 @@ /**

function getProperties(filePath, encoding) {
if (!(0, fs_1.existsSync)(filePath)) {
throw Error("file not found at ".concat(filePath));
if (!(0, node_fs_1.existsSync)(filePath)) {
throw new Error("file not found at ".concat(filePath));
}
return (0, content_1.getProperties)((0, fs_1.readFileSync)(filePath, encoding ? encoding : 'utf-8'));
return (0, content_1.getProperties)((0, node_fs_1.readFileSync)(filePath, encoding !== null && encoding !== void 0 ? encoding : 'utf8'));
}

@@ -21,0 +21,0 @@ exports.getProperties = getProperties;

@@ -7,6 +7,6 @@ import { KeyValueObject } from './';

export declare class Properties {
/** The collection of property object. */
collection: Property[];
/** Object associating keys with their starting line numbers. */
keyLineNumbers: KeyLineNumbers;
/** The collection of property object. */
collection: Property[];
/**

@@ -21,2 +21,6 @@ * Add a property object into a properties object collection.

/**
* Get keys that have collisions (more than one occurrence).
*/
getKeyCollisions(): KeyCollisions[];
/**
* Get the JSON (key/value) representation of the properties.

@@ -27,6 +31,2 @@ *

toJson(): KeyValueObject;
/**
* Get keys that have collisions (more than one occurrence).
*/
getKeyCollisions(): KeyCollisions[];
}

@@ -33,0 +33,0 @@ /**

@@ -9,6 +9,6 @@ "use strict";

function Properties() {
/** The collection of property object. */
this.collection = [];
/** Object associating keys with their starting line numbers. */
this.keyLineNumbers = {};
/** The collection of property object. */
this.collection = [];
}

@@ -43,14 +43,2 @@ /**

/**
* Get the JSON (key/value) representation of the properties.
*
* @returns A key/value representing the properties of the object.
*/
Properties.prototype.toJson = function () {
var keyValueObject = {};
this.collection.forEach(function (property) {
keyValueObject[property.key] = property.value;
});
return keyValueObject;
};
/**
* Get keys that have collisions (more than one occurrence).

@@ -68,2 +56,14 @@ */

};
/**
* Get the JSON (key/value) representation of the properties.
*
* @returns A key/value representing the properties of the object.
*/
Properties.prototype.toJson = function () {
var keyValueObject = {};
this.collection.forEach(function (property) {
keyValueObject[property.key] = property.value;
});
return keyValueObject;
};
return Properties;

@@ -70,0 +70,0 @@ }());

@@ -7,10 +7,10 @@ /**

content: string;
/** Is the line object a continuation from a previous line? */
isMultiline: boolean;
/** True if the line continues, otherwise false. */
continues: boolean;
/** True if the line is blank, otherwise false. */
isBlank: boolean;
/** True if the line is a comment, otherwise false. */
isComment: boolean;
/** True if the line is blank, otherwise false. */
isBlank: boolean;
/** Is the line object a continuation from a previous line? */
isMultiline: boolean;
/**

@@ -17,0 +17,0 @@ * Create a new line object.

@@ -17,9 +17,9 @@ "use strict";

this.continues = false;
/** True if the line is blank, otherwise false. */
this.isBlank = false;
/** True if the line is a comment, otherwise false. */
this.isComment = false;
/** True if the line is blank, otherwise false. */
this.isBlank = false;
this.content = line.trimStart();
this.isMultiline = isMultiline;
if (!this.content.length) {
if (this.content.length === 0) {
// Line is blank.

@@ -31,3 +31,3 @@ this.isBlank = true;

// Line is a comment.
this.isComment = !!this.content.match(/^[!#]/);
this.isComment = !!/^[!#]/.test(this.content);
}

@@ -34,0 +34,0 @@ if (!this.isComment) {

@@ -6,14 +6,6 @@ import { PropertyLine } from './property-line';

export declare class Property {
/** The line number at which the property starts. */
startingLineNumber: number;
/** The content of one or multiple lines when applicable. */
linesContent: string;
/** Positions of the newline characters if any. */
newlinePositions: number[];
/** Starting line numbers of property objects with the same key. */
keyCollisionLines: number[];
/** The length of the delimiter, including its whitespace characters. */
delimiterLength: number | undefined;
/** The starting position of the delimiter separating the key from the value. */
delimiterPosition: number | undefined;
/** The length of the delimiter, including its whitespace characters. */
delimiterLength: number | undefined;
/** The property key, including its escaped characters. */

@@ -23,8 +15,16 @@ escapedKey: string;

escapedValue: string;
/** Was the property's key used more than once? */
hasKeyCollisions: boolean;
/** The property key (unescaped). */
key: string;
/** Starting line numbers of property objects with the same key. */
keyCollisionLines: number[];
/** The content of one or multiple lines when applicable. */
linesContent: string;
/** Positions of the newline characters if any. */
newlinePositions: number[];
/** The line number at which the property starts. */
startingLineNumber: number;
/** The property value (unescaped). */
value: string;
/** Was the property's key used more than once? */
hasKeyCollisions: boolean;
/** Does the key definition spread across multiple lines? */

@@ -31,0 +31,0 @@ private hasMultilineKey;

@@ -15,6 +15,2 @@ "use strict";

function Property(propertyLine, startingLineNumber) {
/** Positions of the newline characters if any. */
this.newlinePositions = [];
/** Starting line numbers of property objects with the same key. */
this.keyCollisionLines = [];
/** The property key, including its escaped characters. */

@@ -24,8 +20,12 @@ this.escapedKey = '';

this.escapedValue = '';
/** Was the property's key used more than once? */
this.hasKeyCollisions = false;
/** The property key (unescaped). */
this.key = '';
/** Starting line numbers of property objects with the same key. */
this.keyCollisionLines = [];
/** Positions of the newline characters if any. */
this.newlinePositions = [];
/** The property value (unescaped). */
this.value = '';
/** Was the property's key used more than once? */
this.hasKeyCollisions = false;
/** Does the key definition spread across multiple lines? */

@@ -46,3 +46,3 @@ this.hasMultilineKey = false;

Property.prototype.addLine = function (propertyLine) {
if (this.linesContent.length) {
if (this.linesContent.length > 0) {
this.newlinePositions.push(this.linesContent.length);

@@ -60,3 +60,3 @@ }

if (!this.hasNoKey) {
this.escapedKey = this.linesContent.substring(0, this.delimiterPosition);
this.escapedKey = this.linesContent.slice(0, this.delimiterPosition);
this.key = this.unescape(this.escapedKey, this.startingLineNumber);

@@ -66,3 +66,3 @@ }

if (!this.hasNoValue) {
this.escapedValue = this.linesContent.substring(this.delimiterPosition + this.delimiterLength);
this.escapedValue = this.linesContent.slice(this.delimiterPosition + this.delimiterLength);
this.value = this.unescape(this.escapedValue, this.startingLineNumber);

@@ -87,40 +87,47 @@ }

var unescapedContent = '';
for (var position = 0, character = escapedContent[0]; position < escapedContent.length; position++, character = escapedContent[position]) {
for (var character = escapedContent[0], position = 0; position < escapedContent.length; position++, character = escapedContent[position]) {
if (character === '\\') {
var nextCharacter = escapedContent[position + 1];
if (nextCharacter === 'f') {
// Formfeed/
unescapedContent += '\f';
position++;
}
else if (nextCharacter === 'n') {
// Newline.
unescapedContent += '\n';
position++;
}
else if (nextCharacter === 'r') {
// Carriage return.
unescapedContent += '\r';
position++;
}
else if (nextCharacter === 't') {
// Tab.
unescapedContent += '\t';
position++;
}
else if (nextCharacter === 'u') {
// Unicode character.
var codePoint = escapedContent.substring(position + 2, position + 6);
if (!/[0-9a-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, "' in property starting at line ").concat(startingLineNumber));
switch (nextCharacter) {
case 'f': {
// Formfeed/
unescapedContent += '\f';
position++;
break;
}
unescapedContent += String.fromCharCode(parseInt(codePoint, 16));
position += 5;
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, "' in property starting at line ").concat(startingLineNumber));
}
unescapedContent += String.fromCodePoint(Number.parseInt(codePoint, 16));
position += 5;
break;
}
default: {
// Otherwise the escape character is not required.
unescapedContent += nextCharacter;
position++;
}
}
else {
// Otherwise the escape character is not required.
unescapedContent += nextCharacter;
position++;
}
}

@@ -143,10 +150,10 @@ else {

}
for (var position = 0, character = this.linesContent[0]; position < this.linesContent.length; position++, character = this.linesContent[position]) {
for (var character = this.linesContent[0], position = 0; position < this.linesContent.length; position++, character = this.linesContent[position]) {
// If the character is not a delimiter, check the next one.
if (!/[ \t\f=:]/.test(character)) {
if (!/[\t\f :=]/.test(character)) {
continue;
}
// Check if the delimiter might be escaped.
var prefix = !position ? '' : this.linesContent.substring(0, position);
if (prefix.length) {
var prefix = !position ? '' : this.linesContent.slice(0, position);
if (prefix.length > 0) {
var backslashMatch = prefix.match(/(?<backslashes>\\+)$/);

@@ -163,16 +170,16 @@ if (backslashMatch === null || backslashMatch === void 0 ? void 0 : backslashMatch.groups) {

this.delimiterPosition = position;
this.hasMultilineKey = !!(this.newlinePositions.length && this.newlinePositions[0] > position);
this.hasMultilineKey = !!(this.newlinePositions.length > 0 && this.newlinePositions[0] > position);
// Check if the delimiter starts with a whitespace.
var nextContent = this.linesContent.substring(position);
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) {
if (leadingWhitespace.length > 0) {
delimiter += leadingWhitespace;
nextContent = nextContent.substring(leadingWhitespace.length);
nextContent = nextContent.slice(leadingWhitespace.length);
}
// Check if there is an equal or colon character.
if (/[=:]/.test(nextContent[0])) {
if (/[:=]/.test(nextContent[0])) {
delimiter += nextContent[0];
nextContent = nextContent.substring(1);
nextContent = nextContent.slice(1);
// If an equal or colon character was found, try to get trailing whitespace.

@@ -196,3 +203,3 @@ var trailingWhitespaceMatch = nextContent.match(/^(?<whitespace>\s+)/);

// If the delimiter is after the first newline, mark the key as multiline.
if (this.newlinePositions.length) {
if (this.newlinePositions.length > 0) {
var firstLinePosition = this.newlinePositions[0];

@@ -199,0 +206,0 @@ if (firstLinePosition > this.delimiterPosition) {

{
"name": "properties-file",
"version": "2.0.9",
"version": "2.1.0",
"description": ".properties file parser, JSON converter and Webpack loader.",

@@ -45,7 +45,8 @@ "author": "Avansai (https://avansai.com)",

"scripts": {
"build": "rm -Rf ./lib && tsc && npm run add-import-type && npm run lint && npm test",
"lint": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx --fix .",
"build": "npm run prettier && npm run lint-fix && rm -Rf ./lib && tsc && npm run add-import-type && npm test",
"lint-fix": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx --fix .",
"lint-check": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx .",
"lint-print-config": "eslint --print-config ./eslintrc.yaml",
"prettier": "prettier --write .",
"add-import-type": "node ./src/add-import-type",
"add-import-type": "node ./src/add-import-type.mjs",
"test": "jest --coverage",

@@ -57,4 +58,4 @@ "release": "dotenv -- release-it --only-version"

"@types/jest": "^28.1.6",
"@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"dotenv-cli": "^6.0.0",

@@ -64,14 +65,19 @@ "eslint": "^8.21.0",

"eslint-import-resolver-node": "^0.3.6",
"eslint-import-resolver-typescript": "^3.3.0",
"eslint-import-resolver-typescript": "^3.4.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.7.0",
"eslint-plugin-jest": "^26.8.2",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-unicorn": "^43.0.2",
"jest": "^28.1.3",
"prettier": "^2.7.1",
"prettier-plugin-organize-imports": "^3.0.0",
"release-it": "^15.2.0",
"prettier-plugin-organize-imports": "^3.0.3",
"prettier-plugin-sh": "^0.12.8",
"release-it": "^15.3.0",
"ts-jest": "^28.0.7",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
},
"engines": {
"node": "^14.18.1 || ^16.0.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc