Skip to content
This repository has been archived by the owner on Aug 3, 2022. It is now read-only.

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
ndaidong committed May 22, 2016
1 parent 2cafb8a commit d423651
Show file tree
Hide file tree
Showing 10 changed files with 663 additions and 0 deletions.
1 change: 1 addition & 0 deletions .coveralls.yml
@@ -0,0 +1 @@
repo_token: hFnoanBvXs0SgRpWZsm8MLJu9QDbnloiV
8 changes: 8 additions & 0 deletions .eslintignore
@@ -0,0 +1,8 @@
coverage/*
node_modules/*
dist
**/vendor/*.js
.nyc_output/*
LICENSE
package.json
README.md
390 changes: 390 additions & 0 deletions .eslintrc

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions .jsbeautifyrc
@@ -0,0 +1,24 @@
{
"js": {
"brace_style": "none",
"break_chained_methods": false,
"end_with_comma": false,
"end_with_newline": true,
"eol": "\n",
"eval_code": false,
"indent_size": 2,
"indent_char": " ",
"indent_level": 0,
"indent_with_tabs": false,
"keep_array_indentation": true,
"keep_function_indentation": true,
"preserve_newlines": true,
"space_in_paren": false,
"space_after_anon_function": false,
"space_before_conditional": true,
"unescape_strings": false,
"wrap_line_length": 0,
"wrap_attributes": "auto",
"wrap_attributes_indent_size": 2
}
}
11 changes: 11 additions & 0 deletions .travis.yml
@@ -0,0 +1,11 @@
language: node_js
node_js:
- "6.0.0"
- "5.11.0"
- "5.9"
- "5.0"
- "4.2"
before_script:
- export TZ=Etc/GMT-7
after_success:
- npm run coveralls
8 changes: 8 additions & 0 deletions index.js
@@ -0,0 +1,8 @@
/**
* Starting app
* @ndaidong
**/
'use strict';

exports = module.exports = require('./src/filedb');
exports.version = require('./package').version;
46 changes: 46 additions & 0 deletions package.json
@@ -0,0 +1,46 @@
{
"version": "0.0.1",
"name": "filedb",
"description": "Flat-file based data storage",
"homepage": "http://techpush.net",
"repository": {
"type": "git",
"url": "git@github.com:ndaidong/filedb.git"
},
"author": "Dong Nguyen <ndaidong@gmail.com> (https://twitter.com/ndaidong)",
"main": "./index.js",
"engines": {
"node": ">= 6.0"
},
"scripts": {
"test": "./node_modules/.bin/tape test/start.js | tap-spec",
"coverage": "./node_modules/.bin/nyc tape test/start.js | tap-spec",
"report": "npm run coverage && ./node_modules/.bin/nyc report --reporter=lcov",
"coveralls": "npm run report && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls"
},
"dependencies": {
"bellajs": "latest"
},
"devDependencies": {
"coveralls": "latest",
"nyc": "latest",
"tap-spec": "latest",
"tape": "latest"
},
"keywords": [
"storage",
"database",
"nosql",
"util"
],
"license": "MIT",
"maintainers": [
"ndaidong <ndaidong@gmail.com>"
],
"bugs": {
"url": "https://github.com/ndaidong/filedb/issues"
},
"directories": {
"test": "test"
}
}
68 changes: 68 additions & 0 deletions src/filedb.js
@@ -0,0 +1,68 @@
/**
* FileDB - Flat file based database
* @ndaidong
**/

var bella = require('bellajs');
var fs = require('fs');
var path = require('path');
var exec = require('child_process').execSync;

var _storeDir = './';
var _collections = [];

var fixPath = (p) => {
if (!p) {
return '';
}
p = path.normalize(p);
p += p.endsWith('/') ? '' : '/';
return p;
};

class Collection {
constructor(name, dir) {
this.name = name;
this.dir = dir;
}
}

var FileDB = {
config: (opt) => {
let d = fixPath(opt.path);
if (!fs.existsSync(d)) {
fs.mkdirSync(d);
_storeDir = d;
}
},
addCollection: (col) => {
let name = bella.strtolower(col);
let d = fixPath(_storeDir + name);
if (!fs.existsSync(d)) {
fs.mkdirSync(d);
let c = new Collection(name, d);
_collections.push(c);
return c;
}
return false;
},
removeCollection: (col) => {
let name = bella.strtolower(col);
let d = fixPath(_storeDir + name);
if (!fs.existsSync(d)) {
return exec('rm -rf ' + d);
}
return false;
},
emptyCollection: (col) => {
let name = bella.strtolower(col);
let d = fixPath(_storeDir + name);
if (!fs.existsSync(d)) {
exec('rm -rf ' + d);
return fs.mkdirSync(d);
}
return false;
}
};

module.exports = FileDB;
89 changes: 89 additions & 0 deletions test/specs/main.js
@@ -0,0 +1,89 @@
/**
* Testing
* @ndaidong
*/

/* eslint no-undefined: 0*/
/* eslint no-array-constructor: 0*/
/* eslint no-new-func: 0*/
/* eslint no-console: 0*/

var path = require('path');
var test = require('tape');
var bella = require('bellajs');

var rootDir = '../../../src/';
var AP = require(path.join(rootDir, 'article-parser'));

var sample = {
wordsPerMinute: 500,
blackList: [ 'bing.com', 'yahoo.com' ],
exceptDomain: [ 'google.com', 'apple.com' ],
adsDomain: [ 'twitter.com', 'facebook.com' ],
SoundCloudKey: 'SOUNDCLOUDKEY',
YouTubeKey: 'YOUTUBEKEY',
EmbedlyKey: 'EMBEDLYKEY',
ReadabilityToken: 'READABILITYTOKEN',
htmlRules: {
allowedTags: [
'html', 'body', 'meta', 'link', 'title'
],
allowedAttributes: {
'a': [ 'href' ]
}
}
};

var hasRequiredKeys = (o) => {
var structure = [
'wordsPerMinute',
'blackList',
'exceptDomain',
'adsDomain',
'SoundCloudKey',
'YouTubeKey',
'EmbedlyKey',
'ReadabilityToken',
'htmlRules'
];

return structure.every((k) => {
return bella.hasProperty(o, k);
});
};

var fake = Object.create(AP);

test('Testing "configure" method:', (assert) => {

fake.configure(sample);
let config = fake.getConfig();

assert.comment('(Call config object is C, so:)');
assert.ok(bella.isObject(config), 'C must be an object.');
assert.ok(hasRequiredKeys(config), 'C must have all required keys.');

let a1 = config.SoundCloudKey;
let e1 = sample.SoundCloudKey;
assert.deepEqual(a1, e1, `C.SoundCloudKey must be ${e1}`);

let a2 = config.YouTubeKey;
let e2 = sample.YouTubeKey;
assert.deepEqual(a2, e2, `C.YouTubeKey must be ${e2}`);

let a3 = config.EmbedlyKey;
let e3 = sample.EmbedlyKey;
assert.deepEqual(a3, e3, `C.EmbedlyKey must be ${e3}`);

let a4 = config.ReadabilityToken;
let e4 = sample.ReadabilityToken;
assert.deepEqual(a4, e4, `C.ReadabilityToken must be ${e4}`);

let a5 = config.htmlRules;
let e5 = sample.htmlRules;
assert.deepEqual(a5, e5, 'C.htmlRules must be equal to sample.htmlRules');

assert.deepEqual(config.wordsPerMinute, sample.wordsPerMinute, `C.wordsPerMinute must be ${sample.wordsPerMinute}`);

assert.end();
});
18 changes: 18 additions & 0 deletions test/start.js
@@ -0,0 +1,18 @@
var fs = require('fs');
var path = require('path');

/**
* Import specs
*/

var dirs = [ '' ];
dirs.forEach((dir) => {
let where = './test/specs/' + dir;
if (fs.existsSync(where)) {
fs.readdirSync(where).forEach((file) => {
if (path.extname(file) === '.js') {
require(path.join('.' + where, file));
}
});
}
});

0 comments on commit d423651

Please sign in to comment.