Registry / devops / js-java-properties

js-java-properties

JSON →
library1.1.0jsnpmunverified

A JavaScript/TypeScript library for parsing, modifying, and stringifying Java .properties files while preserving formatting and comments. Version 1.1.0 (stable, released 2024) uses an array-of-lines backing store to allow in-place editing without reformatting, unlike typical parsers that convert to plain objects. Supports ESM and CommonJS, ships TypeScript types, and requires Node >= 20. Provides functions: parse, stringify, listProperties, getProperty, setProperty, toObject, toMap, empty. Handles duplicate keys, comments, multi-line values, and separator styles (':', '=', or space).

npm install js-java-properties
INSTALL
IMPORT
SIG · JS-JAVA-PROPERTIES
J
js-java-properties
devopsjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
import { parse } from 'js-java-properties'
const { parse } = require('js-java-properties')
ESM import is preferred. CommonJS require works in Node >= 20.
stringify
import { stringify } from 'js-java-properties'
import * as props from 'js-java-properties'; props.stringify(propsObj)
stringify is a named export; importing as namespace and calling .stringify is also correct.
Properties (type)
import type { Properties } from 'js-java-properties'
import { Properties } from 'js-java-properties'
Properties is a type/interface, not a runtime value. Use type import for proper TypeScript.
KeyValuePair (type)
import type { KeyValuePair } from 'js-java-properties'
import { KeyValuePair } from 'js-java-properties'
KeyValuePair is a type, not a constructor. Must use type import.
listProperties
import { listProperties } from 'js-java-properties'
import * as props from 'js-java-properties'; props.listProperties(props)
listProperties is a named export. Accepts Properties object and returns iterable of KeyValuePair.

Demonstrates parsing, getting/setting properties, converting to object, listing key-value pairs, creating empty properties and stringifying.

import { parse, empty, stringify, getProperty, setProperty, toObject, listProperties } from 'js-java-properties'; // Parse a properties string const props = parse('key1=value1\nkey2 = value2\n# comment\nkey3: value3'); console.log(props); // { lines: [ 'key1=value1', 'key2 = value2', '# comment', 'key3: value3' ] } // Get a property (case-sensitive) console.log(getProperty(props, 'key2')); // 'value2' // Set a property (adds or updates) setProperty(props, 'key2', 'new-value'); console.log(props.lines); // includes 'key2 = new-value' // Convert to object const obj = toObject(props); console.log(obj); // { key1: 'value1', key2: 'new-value', key3: 'value3' } // List all key-value pairs (including duplicates) for (const { key, value } of listProperties(props)) { console.log(`${key}=${value}`); } // Create empty properties and add lines const emptyProps = empty(); emptyProps.lines.push('newKey=new value'); const output = stringify(emptyProps); console.log(output); // 'newKey=new value\n' // Read from file (Node.js) import fs from 'node:fs'; const fileContent = fs.readFileSync('config.properties', 'utf-8'); const fileProps = parse(fileContent);
Debug
Known issues
gotchagetProperty() returns the last occurrence of a duplicate key, not the first.
fix
If you need first occurrence, use listProperties() and stop on first match.
affects: >=0.0.0
gotchasetProperty() modifies the object in place and returns void. It does not return a new object.
fix
Be careful not to expect a return value; check the updated props object directly.
affects: >=0.0.0
gotchasetProperty() with value undefined removes the key entirely. If you want to set empty string, pass empty string explicitly.
fix
Use setProperty(props, 'key', undefined) to remove; use setProperty(props, 'key', '') to set empty.
affects: >=0.0.0
gotchaProperties object is mutable; your code may unintentionally modify the internal lines array.
fix
Clone the lines array if you need to preserve original: props.lines = [...props.lines];
affects: >=0.0.0
breakingVersion 1.0.0 dropped support for Node < 20.
fix
Upgrade Node.js to version 20 or later.
affects: >=1.0.0
deprecatedNo functions are currently deprecated, but the Properties type may be extended in future minor versions.
fix
Prepare for possible additions by not assuming a fixed shape beyond 'lines'.
affects: >=1.0.0
gotchaMulti-line property values (backslash continuation) are not expanded into single lines in the lines array; each line is stored separately.
fix
Use listProperties() or toObject() to get the combined value.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: (0 , properties.parse) is not a function
Trying to call parse as a default export after a namespace import.
fix
Use named import: import { parse } from 'js-java-properties';
Module not found: Error: Can't resolve 'js-java-properties'
Missing install or incorrect import path. Package is ESM/CJS compatible.
fix
Run npm install js-java-properties or check that package.json includes it.
Cannot find name 'Properties'.
Trying to use Properties type without importing it as a type.
fix
Use import type { Properties } from 'js-java-properties';
Property 'lines' does not exist on type 'void'.
Calling setProperty() and trying to access .lines on its return value (which is void).
fix
setProperty modifies the object in place; access .lines on the original props object.
Uncaught SyntaxError: The requested module 'js-java-properties' does not provide an export named 'default'
Trying to import default from a package that only has named exports.
fix
Use named imports: import { parse, empty, stringify } from 'js-java-properties';
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
js-java-properties — npm install js-java-properties · libregistry