forked from nextup/nextup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfsFunctions.js
More file actions
68 lines (57 loc) · 2 KB
/
fsFunctions.js
File metadata and controls
68 lines (57 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var Promise = require('bluebird');
var fs = Promise.promisifyAll(require('fs'));
var path = require('path');
var saveAsJson = function (item, dir) {
var dir = dir || './json/'
item.file = toFilename(item);
// item.file = item.title
// .replace(/[^\w\s]|_/g, '')
// .replace(/\W+/g, '')
// .replace(/\s+/g, '')
// .replace(/ +?/g, '')
// .replace()
// .toLowerCase();
//if then for directory
// if (archive.indexOf(item.file + '.json') === -1 && main.indexOf(item.file + '.json') === -1){
// scrapeSite(item.link, item.title, item);
// }
return fs.writeFileAsync(path.join(dir, item.file + '.json'), JSON.stringify(item));
};
var toFilename = function (item) {
return item.title
.replace(/[^\w\s]|_/g, '')
.replace(/\W+/g, '')
.replace(/\s+/g, '')
.replace(/ +?/g, '')
.replace()
.toLowerCase();
};
/***
* ______ _
* | ____| | |
* | |__ __ __ _ __ ___ _ __ | |_
* | __| \ \/ /| '_ \ / _ \ | '__|| __|
* | |____ > < | |_) || (_) || | | |_
* |______|/_/\_\| .__/ \___/ |_| \__|
* | |
* |_|
*/
module.exports.saveAsJson = saveAsJson;
module.exports.toFilename = toFilename;
/***
* _______ _
* |__ __| | |
* | | ___ ___ | |_ ___
* | | / _ \/ __|| __|/ __|
* | || __/\__ \| |_ \__ \
* |_| \___||___/ \__||___/
*
*
*/
var executeTest = function () {
t1 = {title: "hello", link: 'www.greg.com', wordunique: 3, wordtable: {'i' : 1, 'like': 1, 'dogs': 1}};
t2 = {title: "hello something esle's aosk agood HPAPY!", link: 'www.asldb.com', wordunique: 3, wordtable: {'i' : 1, 'like': 1, 'dogs': 1}};
saveAsJson(t1);
saveAsJson(t2);
};
// executeTest();