d-properties 1.0.0

D-language parser and serializer for Java-style properties files.


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

d-properties

D-language parser and serializer for Java-style properties files, which conforms to the format specification on Wikipedia.

Usage

import std.stdio;
import d_properties;

Properties props;

// Read properties from a file:
props = Properties("config.properties");
// Read from multiple files (values in subsequent files overwrite earlier ones):
props = Properties("base_config.properties", "extra.properties");
// Add properties from any additional file (or files):
props.addAll("another_file.properties");
props.addAll("yet_another.properties", "auxiliary.properties");
// Add properties from another Properties object:
Properties other = Properties(["key": "value"]);
props.addAll(other);

// Do stuff with the properties:
writeln(props); // Properties is a struct, so it can be converted to a string.
writeln(props["key"]); // Access property values via [].
props["key"] = "new value"; // Set a property like so.
writeln(props.get("unknown_key", "none")); // Get a property, or fallback to a default.

// Use the in operator to check if properties exist:
if ("unknown_key" in props) writeln("Property is present.");
if ("other_key" !in props) writeln("Property is not present.");

try {// Accessing missing properties with [] will throw MissingPropertyException
    writeln(props["unknown_key"]);
} catch (MissingPropertyException e) {
    writeln("Missing property!");
}

// Save to a file:
props.writeToFile("my_props.properties");
// Add a comment to the top of the file:
props.writeToFile("out.properties", "This is a comment");
// Use a different separator between keys and values (default is " = "):
props.writeToFile("out.properties", null, SeparatorStyle.COLON);
Authors:
  • Andrew Lalis <andrewlalisofficial@gmail.com>
Dependencies:
none
Versions:
1.0.0 2021-Oct-01
~main 2021-Oct-01
Show all 2 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 1 downloads this month

  • 1 downloads total

Score:
0.3
Short URL:
d-properties.dub.pm