Comparing version 0.1.2 to 0.2.0
{ | ||
"extends": "airbnb-base" | ||
} |
{ | ||
"name": "enmap", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
const level = require('native-level-promise'); | ||
const path = require('path'); | ||
const { inspect } = require('util'); | ||
const fs = require('fs'); | ||
@@ -37,11 +37,13 @@ /** | ||
this.defer = new Promise(resolve => this.ready = resolve); | ||
if (options.persistent) { | ||
if (!options.name) throw new Error('Must provide a name for the Enmap.'); | ||
if (options.name) this.persistent = options.persistent || true; | ||
if (this.persistent) { | ||
if (!options.name) throw new Error('Must provide a name for a persistent Enmap.'); | ||
this.name = options.name; | ||
//todo: check for "unique" option for the DB name and exit if exists | ||
// todo: check for "unique" option for the DB name and exit if exists | ||
this.validateName(); | ||
this.dataDir = (options.dataDir || 'data'); | ||
this.dataDir = path.resolve(process.cwd(), (options.dataDir || 'data')); | ||
this.persistent = (options.persistent || false); | ||
if (!options.dataDir) { | ||
const fs = require('fs'); | ||
if (!fs.existsSync('./data')) { | ||
@@ -51,3 +53,3 @@ fs.mkdirSync('./data'); | ||
} | ||
this.path = path.join(process.cwd(), this.dataDir, this.name); | ||
this.path = path.join(this.dataDir, this.name); | ||
this.db = new level(this.path); | ||
@@ -66,3 +68,3 @@ this.init(); | ||
const stream = this.db.keyStream(); | ||
stream.on('data', key => { | ||
stream.on('data', (key) => { | ||
this.db.get(key, (err, value) => { | ||
@@ -568,2 +570,2 @@ if (err) console.log(err); | ||
module.exports = Enmap; | ||
module.exports = Enmap; |
@@ -0,0 +0,0 @@ const PersistentCollection = require('../'); |
Sorry, the diff of this file is not supported yet
52285
594