{"id":15659630,"url":"https://github.com/eemeli/dot-properties","last_synced_at":"2025-04-06T02:08:52.653Z","repository":{"id":29042326,"uuid":"120077955","full_name":"eemeli/dot-properties","owner":"eemeli","description":"Parse \u0026 stringify .properties files in JavaScript","archived":false,"fork":false,"pushed_at":"2024-11-20T12:05:40.000Z","size":779,"stargazers_count":23,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T16:49:08.503Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/dot-properties","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eemeli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"eemeli","tidelift":"npm/yaml"}},"created_at":"2018-02-03T09:36:30.000Z","updated_at":"2025-02-04T12:47:08.000Z","dependencies_parsed_at":"2024-06-18T16:01:54.527Z","dependency_job_id":"56071412-49b1-4c57-8feb-c189c784921d","html_url":"https://github.com/eemeli/dot-properties","commit_stats":{"total_commits":74,"total_committers":4,"mean_commits":18.5,"dds":0.05405405405405406,"last_synced_commit":"fe49d2d779528a499c42bf102d04887d4374c2f3"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eemeli%2Fdot-properties","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eemeli%2Fdot-properties/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eemeli%2Fdot-properties/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eemeli%2Fdot-properties/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eemeli","download_url":"https://codeload.github.com/eemeli/dot-properties/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247423515,"owners_count":20936626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T13:17:54.250Z","updated_at":"2025-04-06T02:08:52.634Z","avatar_url":"https://github.com/eemeli.png","language":"JavaScript","funding_links":["https://github.com/sponsors/eemeli","https://tidelift.com/funding/github/npm/yaml"],"categories":[],"sub_categories":[],"readme":"# dot-properties\n\nJavaScript `parse()` and `stringify()` for `.properties` (`text/x-java-properties`) files as defined in [java.util.Properties](https://docs.oracle.com/javase/9/docs/api/java/util/Properties.html#load-java.io.Reader-).\n\nTo install:\n\n```\nnpm install dot-properties\n```\n\nFor usage examples, see [below](#example) or take a look through the project's [test suite](tests/).\n\n## API\n\n### `parse(str: string | Line[] | Node[], path?: boolean | string): object`\n\nParses an input string read from a .properties file into a JavaScript Object\n\nIf the second `path` parameter is true, dots `.` in keys will result in a multi-level object (use a string value to customise). If a parent level is directly assigned a value while it also has a child with an assigned value, the parent value will be assigned to its empty string `''` key. Repeated keys will take the last assigned value. Key order is not guaranteed, but is likely to match the order of the input lines.\n\n### `parseLines(str: string, ast?: false): Line[]`\n\nSplits the input string into an array of logical lines; useful if you want to preserve order, comments and/or empty lines while processing. Used internally by `parse()`.\n\nKey-value pairs are `[key, value]` arrays with string values. Escape sequences in keys and values are parsed. Empty lines are included as empty strings `''`, and comments as strings that start with `#` or `!` characters. Leading whitespace is not included.\n\n### `parseLines(str: string, ast: true): Node[]`\n\nSplits the input string into an array of AST nodes; see [the source](./lib/ast.js) for more details.\n\n### `stringify(input: object, options?: StringifyOptions): string`\n\nStringifies a hierarchical object or an array of lines or nodes to `.properties` format\n\nIf `input` is a hierarchical object, keys will consist of the path parts joined by `.` characters. With array input, string values represent blank or comment lines and string arrays are `[key, value]` pairs. Control characters and `\\` will be appropriately escaped. If the `latin1` option is not set to false, all non-Latin-1 characters will also be `\\u` escaped. Non-empty string lines represent comments, and will have any existing `#` or `!` prefix replaced by the `commentPrefix`.\n\nOutput styling is controlled by the second (optional) `options` parameter; by default a spaced `=` separates the key from the value, `\\n` is the newline separator, lines are folded at 80 characters (at most, splitting at nice places), with subsequent lines indented by four spaces, and comment lines are prefixed with a `#`. `''` as a key value is considered the default, and set as the value of a key corresponding to its parent object's path:\n\n\u003c!-- prettier-ignore --\u003e\n```js\nconst defaultOptions = {\n  commentPrefix: '# ',  // could also use e.g. '!'\n  defaultKey: '',       // YAML 1.1 used '='\n  indent: '    ',       // tabs are also valid\n  keySep: ' = ',        // should have at most one = or :\n  latin1: true,         // default encoding for .properties files\n  lineWidth: 80,        // use null to disable\n  newline: '\\n',        // Windows uses \\r\\n\n  pathSep: '.',         // if non-default, use the same in parse()\n  foldChars: '\\f\\t .'   // preferred characters for line folding\n}\n```\n\n## Example\n\n### `example.properties`\n\n```\n# You are reading the \".properties\" entry.\n! The exclamation mark can also mark text as comments.\n# The key characters =, and : should be written with a preceding\n# backslash to ensure that they are properly loaded. However, there\n# is no need to precede the value characters =, and : by a backslash.\nwebsite = https://en.wikipedia.org/\nlanguage = English\n\n# The backslash below tells the application to continue reading\n# the value onto the next line.\nmessage = Welcome to \\\n          Wikipedia!\n\n# Add spaces to the key\nkey\\ with\\ spaces = This is the value that could be looked up with \\\n                    the key \"key with spaces\".\n\n# Unicode\ntab : \\u0009\n\n# If you want your property to include a backslash, it should be\n# escaped by another backslash\npath c:\\\\wiki\\\\templates\n# However, some editors will handle this automatically\n```\n\n_Source: [Wikipedia](https://en.wikipedia.org/wiki/.properties)_\n\n### `example.js`\n\n```js\nconst fs = require('fs')\nconst { parse, parseLines, stringify } = require('dot-properties')\nconst src = fs.readFileSync('./example.properties', 'utf8')\n\nconst obj = parse(src)\n// { website: 'https://en.wikipedia.org/',\n//   language: 'English',\n//   message: 'Welcome to Wikipedia!',\n//   'key with spaces':\n//    'This is the value that could be looked up with the key \"key with spaces\".',\n//   tab: '',\n//   path: 'c:wiki\\templates' }\n\nconst str = stringify(obj, { lineWidth: 60 })\nconsole.log(str)\n// website = https://en.wikipedia.org/\n// language = English\n// message = Welcome to Wikipedia!\n// key\\ with\\ spaces = This is the value that could be looked \\\n//     up with the key \"key with spaces\".\n// tab = \\t\n// path = c:\\\\wiki\\\\templates\n\nconst lines = parseLines(src)\n// [ '# You are reading the \".properties\" entry.',\n//   '! The exclamation mark can also mark text as comments.',\n//   '# The key characters =, and : should be written with a preceding',\n//   '# backslash to ensure that they are properly loaded. However, there',\n//   '# is no need to precede the value characters =, and : by a backslash.',\n//   [ 'website', 'https://en.wikipedia.org/' ],\n//   [ 'language', 'English' ],\n//   '',\n//   '# The backslash below tells the application to continue reading',\n//   '# the value onto the next line.',\n//   [ 'message', 'Welcome to Wikipedia!' ],\n//   '',\n//   '# Add spaces to the key',\n//   [ 'key with spaces',\n//     'This is the value that could be looked up with the key \"key with spaces\".' ],\n//   '',\n//   '# Unicode',\n//   [ 'tab', '' ],\n//   '',\n//   '# If you want your property to include a backslash, it should be',\n//   '# escaped by another backslash',\n//   [ 'path', 'c:wiki\\templates' ],\n//   '# However, some editors will handle this automatically' ]\n\nconst str2 = stringify(lines.slice(8, 14), { lineWidth: 60 })\nconsole.log(str2)\n// # The backslash below tells the application to continue\n// # reading\n// # the value onto the next line.\n// message = Welcome to Wikipedia!\n//\n// # Add spaces to the key\n// key\\ with\\ spaces = This is the value that could be looked \\\n//     up with the key \"key with spaces\".\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feemeli%2Fdot-properties","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feemeli%2Fdot-properties","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feemeli%2Fdot-properties/lists"}