bcfg: first commit.

This commit is contained in:
Christopher Jeffrey 2017-10-29 07:08:10 -07:00
commit 069ec2a0f0
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
12 changed files with 1470 additions and 0 deletions

11
.babelrc Normal file
View File

@ -0,0 +1,11 @@
{
"presets": [
["env", {
"targets": {
"browsers": ["last 2 versions"]
},
"useBuiltins": "usage",
"loose": true
}]
]
}

98
.eslintrc.json Normal file
View File

@ -0,0 +1,98 @@
{
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 8
},
"root": true,
"rules": {
"array-bracket-spacing": ["error", "never"],
"arrow-parens": ["error", "as-needed", {
"requireForBlockBody": true
}],
"arrow-spacing": "error",
"block-spacing": ["error", "always"],
"brace-style": ["error", "1tbs"],
"camelcase": ["error", {
"properties": "never"
}],
"comma-dangle": ["error", "never"],
"consistent-return": "error",
"eol-last": ["error", "always"],
"eqeqeq": ["error", "always", {
"null": "ignore"
}],
"func-name-matching": "error",
"indent": ["off", 2, {
"SwitchCase": 1,
"CallExpression": {
"arguments": "off"
},
"ArrayExpression": "off"
}],
"handle-callback-err": "off",
"linebreak-style": ["error", "unix"],
"max-len": ["error", {
"code": 80,
"ignorePattern": "function \\w+\\(",
"ignoreUrls": true
}],
"max-statements-per-line": ["error", {
"max": 1
}],
"new-cap": ["error", {
"newIsCap": true,
"capIsNew": false
}],
"new-parens": "error",
"no-buffer-constructor": "error",
"no-console": "off",
"no-extra-semi": "off",
"no-fallthrough": "off",
"no-func-assign": "off",
"no-implicit-coercion": "error",
"no-multi-assign": "error",
"no-multiple-empty-lines": ["error", {
"max": 1
}],
"no-nested-ternary": "error",
"no-param-reassign": "off",
"no-return-assign": "error",
"no-return-await": "off",
"no-shadow-restricted-names": "error",
"no-tabs": "error",
"no-trailing-spaces": "error",
"no-unused-vars": ["error", {
"vars": "all",
"args": "none",
"ignoreRestSiblings": false
}],
"no-use-before-define": ["error", {
"functions": false,
"classes": false
}],
"no-useless-escape": "off",
"no-var": "error",
"nonblock-statement-body-position": ["error", "below"],
"padded-blocks": ["error", "never"],
"prefer-arrow-callback": "error",
"prefer-const": ["error", {
"destructuring": "all",
"ignoreReadBeforeAssign": true
}],
"prefer-template": "off",
"quotes": ["error", "single"],
"semi": ["error", "always"],
"spaced-comment": ["error", "always", {
"exceptions": ["!"]
}],
"space-before-blocks": "error",
"strict": "error",
"unicode-bom": ["error", "never"],
"valid-jsdoc": "error",
"wrap-iife": ["error", "inside"]
}
}

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
build/
node_modules/
npm-debug.log
package-lock.json

10
.npmignore Normal file
View File

@ -0,0 +1,10 @@
.git*
bench/
docs/
build/
src/
test/
node_modules/
binding.gyp
npm-debug.log
package-lock.json

19
Makefile Normal file
View File

@ -0,0 +1,19 @@
all:
@npm run browserify
browserify:
@npm run browserify
webpack:
@npm run webpack
clean:
@npm run clean
lint:
@npm run lint
test:
@npm test
.PHONY: all browserify webpack clean lint test

54
README.md Normal file
View File

@ -0,0 +1,54 @@
# bcfg
Config parser (used for bcoin).
## Usage
``` js
const bcfg = require('bcfg');
const config = bcfg('my-module', {
alias: {
'n': 'network'
}
});
// Inject some custom options first.
config.inject({
some: 'user',
options: 'here'
});
config.load({
// Parse URL hash
hash: true,
// Parse querystring
query: true,
// Parse environment
env: true,
// Parse args
argv: true
});
// Will parse ~/.my-module/my-config.conf (throws on FS error).
config.open('my-config.conf');
// These will cast types and throw on incorrect type.
console.log(config.str('username'));
console.log(config.str('password'));
console.log(config.uint('userid'));
console.log(config.float('percent'));
console.log(config.bool('initialize'));
```
## Contribution and License Agreement
If you contribute code to this project, you are implicitly allowing your code
to be distributed under the MIT license. You are also implicitly verifying that
all code is your original work. `</legalese>`
## License
- Copyright (c) 2017, Christopher Jeffrey (MIT License).
See LICENSE for more info.

18
lib/bcfg.js Normal file
View File

@ -0,0 +1,18 @@
/*!
* bcfg.js - configuration parsing for bcoin
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
* https://github.com/bcoin-org/bcoin
*/
'use strict';
const Config = require('./config');
function bcfg(module, options) {
return new Config(module, options);
}
bcfg.config = bcfg;
bcfg.Config = Config;
module.exports = bcfg;

1173
lib/config.js Normal file

File diff suppressed because it is too large Load Diff

3
lib/fs-browser.js Normal file
View File

@ -0,0 +1,3 @@
'use strict';
exports.unsupported = true;

3
lib/fs.js Normal file
View File

@ -0,0 +1,3 @@
'use strict';
module.exports = require('fs');

48
package.json Normal file
View File

@ -0,0 +1,48 @@
{
"name": "bcfg",
"version": "0.0.0",
"description": "Config parser for bcoin",
"keywords": [
"conf",
"config"
],
"license": "MIT",
"repository": "git://github.com/bcoin-org/bcfg.git",
"homepage": "https://github.com/bcoin-org/bcfg",
"bugs": {
"url": "https://github.com/bcoin-org/bcfg/issues"
},
"author": "Christopher Jeffrey <chjjeffrey@gmail.com>",
"main": "./lib/bcfg.js",
"scripts": {
"browserify": "browserify -s bcfg lib/bcfg.js | uglifyjs -c > bcfg.js",
"clean": "rm -f bcfg.js",
"lint": "eslint lib/ test/ || exit 0",
"test": "mocha --reporter spec test/*-test.js",
"webpack": "webpack --config webpack.config.js"
},
"devDependencies": {
"babelify": "^7.3.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"browserify": "^14.5.0",
"eslint": "^4.9.0",
"level-js": "^2.2.4",
"mocha": "^4.0.1",
"uglifyjs-webpack-plugin": "^1.0.0-beta.3",
"uglify-es": "^3.1.3",
"webpack": "^3.8.1"
},
"engines": {
"node": ">=7.6.0"
},
"browser": {
"./lib/fs": "./lib/fs-browser.js"
},
"browserify": {
"transform": [
"babelify"
]
}
}

29
webpack.config.js Normal file
View File

@ -0,0 +1,29 @@
'use strict';
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
target: 'web',
entry: {
'bcfg': './lib/bcfg'
},
output: {
library: 'bcfg',
libraryTarget: 'umd',
path: __dirname,
filename: '[name].js'
},
resolve: {
modules: ['node_modules'],
extensions: ['-browser.js', '.js', '.json']
},
module: {
rules: [{
test: /\.js$/,
loader: 'babel-loader'
}]
},
plugins: [
new UglifyJsPlugin()
]
};