# properties 2.1.1

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




## Installing
```
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add properties
```
Published: 2024-06-07T09:03:05.209152Z
Expected archive SHA-256: 333f427dd4ed07bdbe8c75b9ff864a1e70b5d7a8426a2e8bdd457b65ae5ac598

Available in cache; verification: upstream_checksum
## Direct dependencies
- meta: ^1.0.0

## Package README (untrusted upstream documentation)
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

```dart
Properties p = Properties.fromFile(filepath);
```

- get a property out of it

```dart
String value = p.get('test.key.1');
```

..optionally providing a default value..

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

..or a default key..

```dart
String defkey = p.get('test.key.X', defkey:'test.key.1');
```

- get an int, a double or a bool value

```dart
int anInt = p.getInt('test.key.integer');
double aDouble = p.getDouble('test.key.double');
bool aBool = p.getBool('test.key.bool');
```

- get a list

```dart
List<String> list = p.getList('test.key.listofvalues');
```

- add a brand new property, choosing whether to overwrite an existing entry or not

```dart
bool added = p.add('test.key.3', 'value 3', true);
```

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

```dart
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

```dart
String jsonexport = p.toJSON([prefix, suffix]);
```

- filter and extract property entries that matches custom conditions

```dart
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](https://github.com/vaind/properties.dart/pull/10))

## 2.1.0

* Add delete(key) API ([#7](https://github.com/vaind/properties.dart/pull/7))
* Add saveToFile(path) API ([#7](https://github.com/vaind/properties.dart/pull/7))

## 2.0.0

* Add null-safety. ([#1](https://github.com/vaind/properties.dart/pull/1))
* Switch values to UTF-16 ([#3](https://github.com/vaind/properties.dart/pull/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:

  ```dart
  // 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

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

## 0.2.0 - 17-02-2013

* Added some tools to work with JSON objects too

   ```dart
   // 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.







 
