obj-chain-core
Version:
fluent chaining for obj with dot-prop access
125 lines (95 loc) • 3.82 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>plugins/ConfigPlugin.js - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="ObjChain.html">ObjChain</a><ul class='methods'><li data-type='method'><a href="ObjChain.html#.init">init</a></li><li data-type='method'><a href="ObjChain.html#escape">escape</a></li><li data-type='method'><a href="ObjChain.html#extend">extend</a></li><li data-type='method'><a href="ObjChain.html#has">has</a></li><li data-type='method'><a href="ObjChain.html#setIfNotEmpty">setIfNotEmpty</a></li><li data-type='method'><a href="ObjChain.html#toString">toString</a></li><li data-type='method'><a href="ObjChain.html#use">use</a></li><li data-type='method'><a href="ObjChain.html#val">val</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html"></a></li><li><a href="global.html#configPlugin">configPlugin</a></li><li><a href="global.html#flow">flow</a></li><li><a href="global.html#remove">remove</a></li><li><a href="global.html#set">set</a></li><li><a href="global.html#write">write</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">plugins/ConfigPlugin.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>const ConfigStore = require('configstore')
function configDir(configPath) {
const pths = configPath.split('/')
pths.pop()
const configDirStr = pths.join('/')
return configDirStr
}
/**
* @param {ObjChain} chain
* @param {string} [name]
*/
function configPlugin(chain, name) {
const config = new ConfigStore(name || chain.pkg.name)
chain.config = config
chain.clear = config.clear
chain.size = config.size
chain.path = config.path
chain.data = config.all
chain.configDir = () => configDir(config.path)
// putting these as middleware instead
// chain.get = config.get
// chain.update = config.update
// chain.has = config.has
// chain.del = config.delete
// chain.delete = config.delete
// chain.set = config.set
// https://github.com/rauschma/openurl/blob/master/openurl.js
// open(config.path)
const configMiddleware = {
set(key, val) {
config.set(key, val)
},
save() {
// require('fliplog').quick('saving', config, config.all)
// trigger getter and setter
const all = config.all
config.all = all
},
get(key) {
return config.get(key)
},
delete(key) {
return config.delete(key)
},
has(key) {
return config.has(key)
},
}
chain.use({
middleware: configMiddleware,
configName(newName) {
return configPlugin(this, newName)
},
})
}
const ConfigPlugin = configPlugin
module.exports = ConfigPlugin
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Fri Apr 28 2017 01:03:22 GMT-0700 (PDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>