Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

properties-reader

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

properties-reader - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

test/bindToServerTest.js

58

package.json
{
"name": "properties-reader",
"description": "Properties file reader for Node.js",
"version": "0.0.4",
"author": { "name": "Steve King", "email": "steve@mydev.co" },
"contributors": [ { "name": "Steve King", "email": "steve@mydev.co" } ],
"dependencies": {
},
"devDependencies": {
"unit-test": "*"
},
"keywords": [ "properties", "ini", "parser"],
"repository": { "type": "git", "url": "git://github.com/steveukx/properties" },
"main": "src/PropertiesReader",
"bin": {},
"scripts": {
"test": "node test/runner.js"
},
"config": {},
"engines": {
"node": ">= 0.4.1"
}
"name": "properties-reader",
"description": "Properties file reader for Node.js",
"version": "0.0.5",
"author": {
"name": "Steve King",
"email": "steve@mydev.co"
},
"contributors": [
{
"name": "Steve King",
"email": "steve@mydev.co"
}
],
"dependencies": {
"mkdirp": "~0.3.5"
},
"devDependencies": {
"unit-test": "*"
},
"keywords": [
"properties",
"ini",
"parser"
],
"repository": {
"type": "git",
"url": "git://github.com/steveukx/properties"
},
"main": "src/PropertiesReader",
"bin": {},
"scripts": {
"test": "node test/runner.js"
},
"config": {},
"engines": {
"node": ">= 0.4.1"
}
}

@@ -152,3 +152,47 @@ (function() {

/**
* Binds the current properties object and all values in it to the supplied express app.
*
* @param {Object} app The express app (or any object that has a `set` function)
* @param {String} [basePath] The absolute prefix to use for all path properties - defaults to the cwd.
* @param {Boolean} [makePaths=false] When true will attempt to create the directory structure to any path property
*/
PropertiesReader.prototype.bindToExpress = function(app, basePath, makePaths) {
var Path = require('path');
if (!/\/$/.test(basePath = basePath || process.cwd())) {
basePath += '/';
}
this.each(function (key, value) {
if (value && /\.(path|dir)$/.test(key)) {
value = Path.join(basePath, Path.relative(basePath, value));
this.set(key, value);
try {
var directoryPath = /dir$/.test(key) ? value : Path.dirname(value);
if (makePaths) {
require('mkdirp').sync(directoryPath);
}
else if (!require('fs').statSync(directoryPath).isDirectory()) {
throw new Error("Path is not a directory that already exists");
}
}
catch (e) {
throw new Error("Unable to create directory " + value);
}
}
app.set(key, this.get(key));
if(/^browser\./.test(key)) {
app.locals[key.substr(8)] = this.get(key);
}
}, this);
app.set('properties', this);
return this;
};
PropertiesReader.builder = function(sourceFile) {

@@ -155,0 +199,0 @@ return new PropertiesReader(sourceFile);

@@ -11,14 +11,22 @@

tempFile.nextName = (tempFile.nextName || 0) + 1;
(tempFile.files = tempFile.files || []).push(__dirname + '/temp_file_' + tempFile.nextName + '.properties');
tempFile.files.push(__dirname + '/temp_file_' + tempFile.nextName + '.properties');
FileSystem.writeFileSync(tempFile.files[tempFile.files.length - 1], content, 'utf-8');
}
tempFile.pushDir = function (path) {
tempFile.dirs.push(path);
return path;
};
function givenFilePropertiesReader(content) {
tempFile(content);
properties = propertiesReader(tempFile.files[tempFile.files.length - 1]);
return properties;
}
module.exports = new TestCase("Repeat Calls", {
module.exports = new TestCase("General reader functionality", {
setUp: function() {
tempFile.files = tempFile.files || [];
tempFile.dirs = tempFile.dirs || [];
},

@@ -34,2 +42,9 @@

}
while(tempFile.dirs && tempFile.dirs.length) {
var dirPath = tempFile.dirs.pop();
try {
FileSystem.rmdirSync(dirPath);
}
catch(e) {}
}
},

@@ -53,4 +68,3 @@

Assertions.assertEquals(properties.length, 2, 'Blank lines are not stored as properties');
}
,
},

@@ -62,3 +76,12 @@ 'test Properties can be read back via their dot notation names': function() {

Assertions.assertEquals(properties.path().foo.bar, 'A Value', 'Read back along dot notation paths foo.bar');
},
'test Sets properties into an app': function () {
var app = {set: Sinon.spy()};
var properties = givenFilePropertiesReader('\n\nsome.property=Value\n\nfoo.bar = A Value').bindToExpress(app);
Assertions.assert(app.set.withArgs('properties', properties).calledOnce, 'The complete properties object should be set as "properties"');
Assertions.assert(app.set.withArgs('some.property', 'Value').calledOnce, 'Sets all properties');
Assertions.assert(app.set.withArgs('foo.bar', 'A Value').calledOnce, 'Sets all properties');
}
});

@@ -20,3 +20,3 @@

module.exports = new TestCase("Repeat Calls", {
module.exports = new TestCase("Reading properties with sections", {

@@ -23,0 +23,0 @@ setUp: function() {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc