{"id":41321,"library":"js-java-properties","title":"js-java-properties","description":"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).","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/mdvorak/js-java-properties","tags":["javascript","java","properties","parser","formatter","typescript"],"install":[{"cmd":"npm install js-java-properties","lang":"bash","label":"npm"},{"cmd":"yarn add js-java-properties","lang":"bash","label":"yarn"},{"cmd":"pnpm add js-java-properties","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM import is preferred. CommonJS require works in Node >= 20.","wrong":"const { parse } = require('js-java-properties')","symbol":"parse","correct":"import { parse } from 'js-java-properties'"},{"note":"stringify is a named export; importing as namespace and calling .stringify is also correct.","wrong":"import * as props from 'js-java-properties'; props.stringify(propsObj)","symbol":"stringify","correct":"import { stringify } from 'js-java-properties'"},{"note":"Properties is a type/interface, not a runtime value. Use type import for proper TypeScript.","wrong":"import { Properties } from 'js-java-properties'","symbol":"Properties (type)","correct":"import type { Properties } from 'js-java-properties'"},{"note":"KeyValuePair is a type, not a constructor. Must use type import.","wrong":"import { KeyValuePair } from 'js-java-properties'","symbol":"KeyValuePair (type)","correct":"import type { KeyValuePair } from 'js-java-properties'"},{"note":"listProperties is a named export. Accepts Properties object and returns iterable of KeyValuePair.","wrong":"import * as props from 'js-java-properties'; props.listProperties(props)","symbol":"listProperties","correct":"import { listProperties } from 'js-java-properties'"}],"quickstart":{"code":"import { parse, empty, stringify, getProperty, setProperty, toObject, listProperties } from 'js-java-properties';\n\n// Parse a properties string\nconst props = parse('key1=value1\\nkey2 = value2\\n# comment\\nkey3: value3');\nconsole.log(props);\n// { lines: [ 'key1=value1', 'key2 = value2', '# comment', 'key3: value3' ] }\n\n// Get a property (case-sensitive)\nconsole.log(getProperty(props, 'key2')); // 'value2'\n\n// Set a property (adds or updates)\nsetProperty(props, 'key2', 'new-value');\nconsole.log(props.lines); // includes 'key2 = new-value'\n\n// Convert to object\nconst obj = toObject(props);\nconsole.log(obj); // { key1: 'value1', key2: 'new-value', key3: 'value3' }\n\n// List all key-value pairs (including duplicates)\nfor (const { key, value } of listProperties(props)) {\n  console.log(`${key}=${value}`);\n}\n\n// Create empty properties and add lines\nconst emptyProps = empty();\nemptyProps.lines.push('newKey=new value');\nconst output = stringify(emptyProps);\nconsole.log(output); // 'newKey=new value\\n'\n\n// Read from file (Node.js)\nimport fs from 'node:fs';\nconst fileContent = fs.readFileSync('config.properties', 'utf-8');\nconst fileProps = parse(fileContent);","lang":"typescript","description":"Demonstrates parsing, getting/setting properties, converting to object, listing key-value pairs, creating empty properties and stringifying."},"warnings":[{"fix":"If you need first occurrence, use listProperties() and stop on first match.","message":"getProperty() returns the last occurrence of a duplicate key, not the first.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Be careful not to expect a return value; check the updated props object directly.","message":"setProperty() modifies the object in place and returns void. It does not return a new object.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use setProperty(props, 'key', undefined) to remove; use setProperty(props, 'key', '') to set empty.","message":"setProperty() with value undefined removes the key entirely. If you want to set empty string, pass empty string explicitly.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Clone the lines array if you need to preserve original: props.lines = [...props.lines];","message":"Properties object is mutable; your code may unintentionally modify the internal lines array.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Upgrade Node.js to version 20 or later.","message":"Version 1.0.0 dropped support for Node < 20.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Prepare for possible additions by not assuming a fixed shape beyond 'lines'.","message":"No functions are currently deprecated, but the Properties type may be extended in future minor versions.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use listProperties() or toObject() to get the combined value.","message":"Multi-line property values (backslash continuation) are not expanded into single lines in the lines array; each line is stored separately.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'1.1.0':22 '20':60 '2024':25 'allow':35 'array':29 'array-of-lin':28 'back':32 'comment':20,74 'commonj':53 'convert':46 'duplic':72 'edit':39 'empti':70 'esm':51 'file':15 'format':18 'formatt':88 'function':62 'getproperti':66 'handl':71 'in-plac':36 'java':3,13,85 'javascript':84 'javascript/typescript':6 'js':2 'js-java-properti':1 'key':73 'librari':7 'line':31,77 'listproperti':65 'modifi':10 'multi':76 'multi-lin':75 'node':59 'object':49 'pars':9,63 'parser':44,87 'place':38 'plain':48 'preserv':17 'properti':4,14,86 'provid':61 'reformat':41 'releas':24 'requir':58 'separ':80 'setproperti':67 'ship':54 'space':83 'stabl':23 'store':33 'stringifi':12,64 'style':81 'support':50 'tomap':69 'toobject':68 'type':56 'typescript':55,89 'typic':43 'unlik':42 'use':26 'valu':78 'version':21 'without':40","created_at":"2026-06-04T18:51:50.656804+00:00","updated_at":"2026-06-04T18:51:50.656804+00:00","problems":[{"fix":"Use named import: import { parse } from 'js-java-properties';","cause":"Trying to call parse as a default export after a namespace import.","error":"TypeError: (0 , properties.parse) is not a function"},{"fix":"Run npm install js-java-properties or check that package.json includes it.","cause":"Missing install or incorrect import path. Package is ESM/CJS compatible.","error":"Module not found: Error: Can't resolve 'js-java-properties'"},{"fix":"Use import type { Properties } from 'js-java-properties';","cause":"Trying to use Properties type without importing it as a type.","error":"Cannot find name 'Properties'."},{"fix":"setProperty modifies the object in place; access .lines on the original props object.","cause":"Calling setProperty() and trying to access .lines on its return value (which is void).","error":"Property 'lines' does not exist on type 'void'."},{"fix":"Use named imports: import { parse, empty, stringify } from 'js-java-properties';","cause":"Trying to import default from a package that only has named exports.","error":"Uncaught SyntaxError: The requested module 'js-java-properties' does not provide an export named 'default'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/mdvorak/js-java-properties#readme","github":"https://github.com/mdvorak/js-java-properties","docs":null,"changelog":null,"pypi":null,"npm":"js-java-properties","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}