Added definition for properties-reader. (#18408)

* Added definition for properties-reader.

* Improved definition for properties-reader.

* Removed object reference from properties-reader.
This commit is contained in:
Goldsmith42 2017-07-27 17:07:41 +02:00 committed by Andy
parent 1abd6ee8d6
commit a05eb94880
4 changed files with 74 additions and 0 deletions

26
types/properties-reader/index.d.ts vendored Normal file
View File

@ -0,0 +1,26 @@
// Type definitions for properties-reader 0.0
// Project: https://github.com/steveukx/properties
// Definitions by: Zlatko Andonovski <https://github.com/Goldsmith42/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace PropertiesReader {
type Value = string|number|boolean;
interface Reader {
get(propertyName: string): Value|null;
getRaw(propertyName: string): string|null;
path(): {};
append(path: string): Reader;
read(properties: string): Reader;
set(propertyName: string, value: Value): Reader;
length: number;
each(iterator: (key: string, value: Value) => void): Reader;
each<T>(iterator: (this: T, key: string, value: Value) => void, scope: T): Reader;
getAllProperties(): { [key: string]: Value; };
clone(): Reader;
}
}
declare function PropertiesReader(path: string): PropertiesReader.Reader;
export = PropertiesReader;

View File

@ -0,0 +1,25 @@
// Trying some things from the official documentation: https://github.com/steveukx/properties/blob/master/README.md
import PropertiesReader = require('properties-reader');
let properties = PropertiesReader('/path/to/properties.file');
// Fully qualified name
let property = properties.get('some.property.name');
// Yeah, so we have no way of doing this properly.
property = (<any> properties.path()).some.property.name;
properties = properties.append('/another.file').append('/yet/another.file');
properties = properties.read('some.property = Value \n another.property = Another Value');
properties = properties.set('property.name', 'Property Value');
properties.get('main.some.thing') === 'foo';
properties.get('blah.some.thing') === 'bar';
const propertiesCount: number = properties.length;
const raw: string|null = properties.getRaw('path.to.prop');
properties = properties.each((key, value) => {});
properties = properties.each(function(key, value) {
this.x = 5;
}, { x: 3 });
const value = properties.getAllProperties()["myKey"];

View File

@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"properties-reader-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }