Viewing version 2.1.1. Open the latest package page.

properties

2.1.1

A simple library to manage properties file (and something more) in Dart

Download archive

Readme

Properties

Properties is a simple library to manage properties files (and something more) in Dart.

The project aim is to provide a simple and lightweight implementation of properties file management for Dart adding some useful but not so common features. Code and usage are very straightforward, just have a look at the Getting Started section below.

To know something more about the released version have a look at the [CHANGELOG][changelog] to find the version that works best for you.

Getting started

The best way to get immediately started is to have a look at the unit tests provided along with the source code.

Anyway you can go on reading this quick intro.

Using Properties you can:

  • create a new properties instance from file
Properties p = Properties.fromFile(filepath);
  • get a property out of it
String value = p.get('test.key.1');

..optionally providing a default value..

String defval = p.get('test.key.X', defval:'value X');

..or a default key..

String defkey = p.get('test.key.X', defkey:'test.key.1');
  • get an int, a double or a bool value
int anInt = p.getInt('test.key.integer');
double aDouble = p.getDouble('test.key.double');
bool aBool = p.getBool('test.key.bool');
  • get a list
List<String> list = p.getList('test.key.listofvalues');
  • add a brand new property, choosing whether to overwrite an existing entry or not
bool added = p.add('test.key.3', 'value 3', true);

and then listen to "property added" or "property updated" events

p.onAdd.listen((AddEvent e) {
        eventType = e.type;
        key = e.key;
        value = e.value;
});
  • export the content as a JSON sting, optionally choosing to export key having a given prefix and/or suffix
String jsonexport = p.toJSON([prefix, suffix]);
  • filter and extract property entries that matches custom conditions
Map<String,String> filtered = p.every((s) => s.startsWith('test'));

Running Tests

To run the tests just run the test/properties_test.dart file.

Some Limits

Output on file is not supported (yet!).

Changelog

Changelog

2.1.1

  • Move the dependency on test package to dev_dependencies (#10)

2.1.0

  • Add delete(key) API (#7)
  • Add saveToFile(path) API (#7)

2.0.0

  • Add null-safety. (#1)
  • Switch values to UTF-16 (#3)

1.0.0 - 2022-01-30

  • Update to Dart SDK 2.0+

0.5.4 - beta

  • Compatibility update for SDK 0.5.13+1.r23552
  • Getters and setters using [].
  • Write to file method first working implementation and fixes.

0.5.3

  • Fixed error on Event.
  • Fixed carriage return problem on line parsing.
  • Minor code improvements on merge and other.
  • Deprecated enable/disable events triggering.

0.5.2+1 - 21-03-2013

  • Compatibility update for SDK 0.4.2

0.5.2 - 21-03-2013

  • Fixed a bug on merge methods, now managing existing empty properties without overwriting them in any case.
  • Improved testing on merge methods.
  • Now managing special characters for values decoding as UTF-8 the bytes read from file.

0.5.1 - 17-03-2013

  • Fixed a bug on event triggering and management.
  • Code refactoring to improve properties management.

0.5 - 16-03-2013

  • Now files are read as bytes enabling deeper property management features.
  • Added multi-line value support.
  • Now the first non-escaped equal is parsed as key-value separator.
  • Added getBool method with customizable evaluator.
  • Minor doc improvements.
  • Unit tests improvements.

0.4.4 - 16-03-2013

  • Added new named constructor fromMap.
  • Added getList method to get a list out of a property's value.
  • Now every method returns a Properties instance instead of a Map.
  • Minor code improvements.
  • Minor doc improvements.

0.4.3 - 12-03-2013

  • Added support for defaults (value and key) on getter methods.
  • Added property updated event support.
  • Now events may be enabled/disabled.
  • Some minor, implementation fixes.

0.4.2 - 03-03-2013

  • Minor fixes.
  • Added two new methods to get integer and double out of a property.

0.4.1 - 02-03-2013

  • Project structure refactoring in order to be published with PUB.

0.4.0 - 27-02-2013

  • the method everyKey() is now every() and may optionally filter on property's value too;
  • added AddEvent? class, extending PropertiesEvent?, having key and value properties set to the corresponding values of the newly added property;
  • add key has now an additional optional parameter to decide whether to overwrite existing property, if any;
  • improved doc and tests.

0.3.0 - 20-02-2013

  • addFromXXX methods have been renamed into mergeXXX, giving the user the capability to choose whether to overwrite or keep existing matching properties:

    // dinamically merge properties from input Properties object into the
    // current instance's properties, without overwriting eventually existing   properties
    p.merge(anotherPropertiesInstance, false);
    
    // dinamically merge properties from input JSON object into the
    // current instance's properties, overwriting existing ones
    p.mergeJSON('{"test.key.3":"value 3","test.key.4":"value 4"}', true);
    
  • added very simple event management: now one may listen to "add property" events triggered when a new property is added at runtime

    p.onAdd.listen((PropertiesEvent e) => print("Received: " + e.type));
    

0.2.0 - 17-02-2013

  • Added some tools to work with JSON objects too

    // create a new instance from a JSON map
    Properties p = new Properties.fromJSON(jsonMap);
    
    // export the (whole) content as a JSON map
    p.toJSON(prefix:"keyprefix", suffix:"keysuffix");
    
    // dinamically add new properties to the current instance from JSON
    p.addFromJSON('{"test.key.3":"value 3","test.key.4":"value 4"}');
    

0.1.0 - 16-02-2013

  • First release: basic tools, support for plain old properties files.

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add 'properties:2.1.1'
pubspec.yaml
name: properties
version: 2.1.1
description: A simple library to manage properties file (and something more) in Dart
repository: https://github.com/vaind/properties.dart

environment:
  sdk: '>=2.12.0 <4.0.0'

dependencies:
  meta: ^1.0.0

dev_dependencies:
  test: ^1.0.0

Version history

VersionPublishedArchiveSHA-256
0.4.1On demandDownload291fe475…f96b92
0.4.2On demandDownload011523bd…e7739b
0.4.3On demandDownload75c66a75…bd72cc
0.4.4On demandDownloadf8472ded…1ede01
0.5.0On demandDownload55462bea…24a5da
0.5.1On demandDownloadb353a461…6dbe33
0.5.2On demandDownload64ac2357…c59b62
0.5.2+1On demandDownload4b7b9876…00b663
0.5.3On demandDownload8c669f56…65b5f4
0.5.4On demandDownloadfba23152…ad73a0
1.0.0On demandDownload7b74627a…37bba7
1.0.0+dev.0On demandDownload9027c7ac…9ca3d5
2.0.0On demandDownloadee6e8466…8c903e
2.1.0On demandDownload975daa00…f2d0e4
2.1.1Cached · Upstream SHA-256 matchedDownload333f427d…5ac598

Dependencies

meta "^1.0.0"