steveukx / properties Goto Github PK
View Code? Open in Web Editor NEWProperties reader for Node.js
License: MIT License
Properties reader for Node.js
License: MIT License
Hi I want to covert my ini file which looks like :
info.info1=ans1.
info.info2=ans2.
info3.info4=ans3.
info5.info6=ans4.
to an object:
{ info:{ info1: ans1, info2:ans2 }, info3:{ info4:ans3 }, info5{ info6: ans4 } }
in the version 2.1.1 this was working by
const propertiesReader = require('properties-reader'); const properties = propertiesReader("relative path"); const obj = properties.path();
but now when I updated to the latest version 2.2.0 path
is returning an empty object
in the latest version
const obj = properties.getAllProperties();
is working but i want a nested object
There is no way to remove a property from an existing PropertiesReader instance.
The current implementation, using the fs
module, allows the properties file to be read only from the local file system. A use case I came across needed to access the properties file across a network, via http/https. Could this be added easily enough, or is it too much work or not appropriate?
When using these functions, the value is always returned as a string instead of being inferred.
When presented with properties files that contain thousands of entries, this package can take multiple seconds to parse them. This is substantially slower than a naive line-by-line parse method, and slow enough to make this package infeasible for my use-case.
See this benchmark, which compares properties-reader to a naive solution using string splitting. Here's the output I get:
.read() x 23.15 ops/sec ±1.05% (42 runs sampled)
naive x 2,600 ops/sec ±0.89% (98 runs sampled)
Fastest is naive
I might expect a naive solution to be a bit faster because it needs fewer checks for complex cases like comments and headings, but being two orders of magnitude faster is very surprising.
Hi,
Thanks a lot for your code.
I am new to NodeJS and angular. I want to use your library in my angular app. How to set it up?
Kind Regrads,
Ragha
Given a file with contents
[section1]
s1foo=foo
s1bar=bar
[section2]
s2foo=foo
s2bar=bar
[section3]
s3foo=foo
s3bar=bar
the following code
const PropertiesReader = require('properties-reader');
let properties = PropertiesReader('/path/to/input/file');
properties.set(`section2.s2new`, 'new');
await properties.save('/path/to/output/file');
will result in
[section1]
s1foo=foo
s1bar=bar
[section2]
s2foo=foo
s2bar=bar
[section3]
s3foo=foo
s3bar=bar
[section2]
s2new=new
The use case here is of course modification of an existing ini file. IMO, the expected output would be the addition of the new section property in the pre-existing section, such as
[section1]
s1foo=foo
s1bar=bar
[section2]
s2foo=foo
s2bar=bar
s2new=new
[section3]
s3foo=foo
s3bar=bar
instead of duplicating the section at the bottom with the new property. In this manner, it seems the library does not properly support the addition of new properties in pre-existing sections that are not last in the file, only modification of such section's pre-existing properties. The output above is invalid as many parsers will throw a duplicate section error.
Using saveSections = false has no difference in the behavior, the sections are created anyway after saving the properties file.
Is there a method that can retrieve all the section names in the property files?
Hi,
I'm having an issue when reading a properties file from another path relative to the caller on a Windows machine. Or in other words: I can only use the same path where the script is, which uses the properties file.
//works:
var properties = PropertiesReader('gradle.properties');
//the following combinations don't work:
var properties = PropertiesReader('./props/gradle.properties');
var properties = PropertiesReader('props\gradle.properties');
var properties = PropertiesReader('.\props\gradle.properties');
var properties = PropertiesReader('../gradle.properties');
My machine runs Windows 7 with NodeJs in version 2.14.7 and properties-reader 0.0.15
Thanks for the great library!
Since my VSCode extension depends on it and I have some users requesting a multi-line functionality like
%%SOME_TAG%%=<List>\
<String>server1</String>\
<String>server2</String>\
<String>server3</String>\
</List>
Would it be possible to put a request for this feature?
The initialization with the parameter 'saveSections: false' is not working. I have to enter property-writer.js and set manually to false.
I don't think my title was very good but this is what I mean.
Consider this property file:
app=My App
app.version=2
First this library will create a property called this._propertiesExpanded.app and set it equal to 'My App'. Then it will try to create this._propertiesExpanded.app.version. This will fail because this._propertiesExpanded.app is a string, not an object and it can't have properties.
I could fix it, at least for my own purposes, but I'm a bit confused by the line in the set method:
source = (source[step] = source[step] || {});
What exactly does that do? It seems to be doing a few things at once on that line.
Steps to reproduce:
payload.properties
[__proto__]
polluted = polluted
poc.js:
var propertiesReader = require('properties-reader');
propertiesReader('./payload.properties');
console.log({}.polluted) // logs 'polluted'
when you change the settings "writer: { saveSections: false}", it does not work.
Only if you change the default setting in the property-writer.js to false it works.
From the main explanation, it says that properties contents can be displayed either by 'getAllProperties' or by looping through them with the .each((key, value) => {}) iterator. Sorry for my weak 'culture', but it would be nice if you can provide an example in this the case either with the iterator. Thanks in advance, good job!
How to read other format nls files? Like test.js, in the test.js, there are some key and value like below format:
({
key1: "value1",
key2: "value2",
})
Thanks.
If I have a property like following, can't be read.
address = {
"line1" : "34 SE Sugarcane Avenue",
"line2" : "Apt 101",
"city":"Reston",
"zipcode":12345
}
Autodetecting the type of the properties can be problematic for String values written with digits only and starting with "0".
Example :
terminal.identifier=0111
This will get the number "111" when we want the string "0111"
Hi, thanks for this library! I'm using it to parse Spring-like properties files.
Given a properties file with no header and a dot-separated value:
testkey.nested=testval
In 2.1.1 I used to be able to do:
const propertiesReader = require("properties-reader");
const properties = propertiesReader("test.properties");
properties.path()
This would give an object: { testkey: { nested: 'testval' } }
In 2.2.0, path()
here returns: {}
I thought that it was not possible to create an empty properties object using the propertiesReader constructor and it took me some time looking at the code to figure out that it is possible.
It would be nice adding an example in the documentation. e.g.
const properties = propertiesReader();
properties.set('propName', 'propValue')
await properties.save('outputfile.properties');
Define URL in properties:
[trade]
base.api.url=http://google.com
Call:
const baseApiUrl = generalProperties.read('trade.base.api.url');
Result:
"[object Object]/public/getmarkets"
It's ok if you change the value to something plain
Hello,
I am not sure if I am mistaken, but I have no import-syntax working for properties-reader (using TypeScript).
Documentation:
const propertiesReader = require("properties-reader"); // works fine
const properties = propertiesReader("path");
Trying to use modern import-syntax does not work for me.
import * as propertiesReader from "properties-reader"); // does not work
import {PropertiesReader} from "properties-reader"; // does not work
import {propertiesReader} from "properties-reader"; // does not work
import {PropertiesReader} from "properties-reader/src/properties-reader"; // does not work
[...]
This might not be an issue but just me not understanding why this is not working. I have looked up require to import converters, which would convert the require-statement into one of the import statements above.
I think it is not working because of the unusual directory-structure of npm-properties-reader. Usually an npm module has an index.js file directly in the directory folder exporting all other visible modules.
I think it would be great if properties-reader import-syntax would be fair to conventions.
I wonder if it's possible to have a parametric property into a file.
Let me explain. Suppose into a file I have something like:
[main]
str1 = "stevekx says " + $param1 + "!"
It would be nice, if I could get the str1 value, passing the value of $ param1.
Something like:
var a = properties.get('main.str1', 'hello');
console.log(a) --> stevekx says hello!
Hi Guys,
my project is using the properties files for translations, but without sections. It would be great, if I could dissable the sections on write in a way.
I provided #24 for this - please review and merge at your convenience, if you deem this usefull.
Thx a lot!
Andreas
This is my code:
const PropertiesReader = require('properties-reader');
const filePath = './docs/XBStation.ini';
const props = PropertiesReader(filePath);
props.set('General.Username', 'Nothing on You');
props.save('./docs/_XBStation.ini', (err, data) => { console.log(data); });
May be an enhancement. Initialize from JSON string to facilitate the properties sharing in Node.js worker threads.
const propsReader = require('properties-reader');
//Now
global.env = propsReader(path/to/file/name);
//Future
global.env = propsReader(path/to/file/name, JSON string, writeToFile); //Write to file, if true
For architectural reasons, don't allow threads to read the properties from file. You might know that worker_threads doesn't allow object sharing
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.