Skip to content

Commit

Permalink
various tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Aug 15, 2014
1 parent fe53f4c commit 8a120dc
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 69 deletions.
3 changes: 1 addition & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# editorconfig.org
root = true

[*]
Expand All @@ -8,7 +7,7 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.json]
[package.json]
indent_style = space
indent_size = 2

Expand Down
11 changes: 2 additions & 9 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
{
"node": true,
"es5": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 4,
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true
"unused": "vars",
"strict": true
}
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
language: node_js
node_js:
- '0.10'
- '0.8'
3 changes: 2 additions & 1 deletion configstore.js → index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var path = require('path');
var os = require('os');
var fs = require('graceful-fs');
var osenv = require('osenv');
var userHome = require('user-home');
var assign = require('object-assign');
var mkdirp = require('mkdirp');
var yaml = require('js-yaml');
Expand All @@ -11,7 +12,7 @@ var getTempDir = os.tmpdir || os.tmpDir; //support node 0.8

var user = (osenv.user() || uuid.v4()).replace(/\\/g, '');
var tmpDir = path.join(getTempDir(), user);
var configDir = process.env.XDG_CONFIG_HOME || path.join(osenv.home() || tmpDir, '.config');
var configDir = process.env.XDG_CONFIG_HOME || path.join(userHome || tmpDir, '.config');
var permissionError = 'You don\'t have access to this file.';
var defaultPathMode = parseInt('0700', 8);
var writeFileOptions = { mode: parseInt('0600', 8) };
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"email": "sindresorhus@gmail.com",
"url": "http://sindresorhus.com"
},
"main": "configstore.js",
"repository": "yeoman/configstore",
"scripts": {
"test": "mocha"
Expand All @@ -27,17 +26,18 @@
},
"license": "BSD",
"dependencies": {
"graceful-fs": "~3.0.1",
"js-yaml": "~3.0.1",
"mkdirp": "~0.5.0",
"object-assign": "~0.3.1",
"osenv": "~0.1.0",
"uuid": "~1.4.1"
"graceful-fs": "^3.0.1",
"js-yaml": "^3.1.0",
"mkdirp": "^0.5.0",
"object-assign": "^1.0.0",
"osenv": "^0.1.0",
"user-home": "^1.0.0",
"uuid": "^1.4.1"
},
"devDependencies": {
"mocha": "*"
},
"files": [
"configstore.js"
"index.js"
]
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# configstore [![Build Status](https://secure.travis-ci.org/yeoman/configstore.svg?branch=master)](http://travis-ci.org/yeoman/configstore)

Easily load and persist config without having to think about where and how.
> Easily load and persist config without having to think about where and how.
Config is stored in a YAML file to make it simple for users to edit the config directly themselves. The file is located in `$XDG_CONFIG_HOME` or `~/.config`. Eg: `~/.config/configstore/id-of-your-choosing.yml`


## Example usage
## Usage

```js
var Configstore = require('configstore');
Expand Down
88 changes: 42 additions & 46 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,46 @@
/*global describe, it, beforeEach */
'use strict';
var assert = require('assert');
var fs = require('fs');
var Configstore = require('./configstore');

describe('configstore', function () {
var configstorePath = new Configstore('configstore-test').path;

beforeEach(function () {
fs.unlinkSync(configstorePath);
this.conf = new Configstore('configstore-test');
});

it('.set() and .get()', function () {
this.conf.set('foo', 'bar');
assert.equal(this.conf.get('foo'), 'bar');
});

it('.del()', function () {
this.conf.set('foo', 'bar');
this.conf.del('foo');
assert.notEqual(this.conf.get('foo'), 'bar');
});

it('.all', function () {
this.conf.set('foo', 'bar');
assert.equal(this.conf.all.foo, 'bar');
});

it('.size', function () {
this.conf.set('foo', 'bar');
assert.equal(this.conf.size, 1);
});

it('.path', function () {
this.conf.set('foo', 'bar');
assert(fs.existsSync(this.conf.path));
});

it('should use default value', function () {
var conf = new Configstore('configstore-test', { foo: 'bar' });
assert.equal(conf.get('foo'), 'bar');
});

it('make sure `.all` is always an object', function () {
fs.unlinkSync(configstorePath);
assert.doesNotThrow(function () {this.conf.get('foo')}.bind(this));
});
var Configstore = require('./');
var configstorePath = new Configstore('configstore-test').path;

beforeEach(function () {
fs.unlinkSync(configstorePath);
this.conf = new Configstore('configstore-test');
});

it('.set() and .get()', function () {
this.conf.set('foo', 'bar');
assert.equal(this.conf.get('foo'), 'bar');
});

it('.del()', function () {
this.conf.set('foo', 'bar');
this.conf.del('foo');
assert.notEqual(this.conf.get('foo'), 'bar');
});

it('.all', function () {
this.conf.set('foo', 'bar');
assert.equal(this.conf.all.foo, 'bar');
});

it('.size', function () {
this.conf.set('foo', 'bar');
assert.equal(this.conf.size, 1);
});

it('.path', function () {
this.conf.set('foo', 'bar');
assert(fs.existsSync(this.conf.path));
});

it('should use default value', function () {
var conf = new Configstore('configstore-test', { foo: 'bar' });
assert.equal(conf.get('foo'), 'bar');
});

it('make sure `.all` is always an object', function () {
fs.unlinkSync(configstorePath);
assert.doesNotThrow(function () {this.conf.get('foo')}.bind(this));
});

0 comments on commit 8a120dc

Please sign in to comment.