source files -> src/ folder
This commit is contained in:
1 parent
f006207112
commit
d25f4439fa
144 files changed
No files matched your search
@@ -0,0 +1,68 @@
|
||||
const DOCS = require("./documents.json");
|
||||
|
||||
exports.docs = DOCS;
|
||||
exports.doc = getDocByName;
|
||||
exports.cap = makeCap;
|
||||
// exports.extra = populateExtra;
|
||||
|
||||
function getDocByName(name){
|
||||
if(name && typeof name == "string"){
|
||||
for(var i=0; i<DOCS.length; i++){
|
||||
var doc = DOCS[i];
|
||||
if(doc.name == name){
|
||||
return clone(doc);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}else if(name && name instanceof Array){
|
||||
var docs = [];
|
||||
name.forEach(function(i){
|
||||
var d = getDocByName(i);
|
||||
if(d){
|
||||
docs.push(d);
|
||||
}
|
||||
});
|
||||
return docs;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function clone(obj){
|
||||
if(obj == null || typeof(obj) != 'object')
|
||||
return obj;
|
||||
|
||||
var temp = obj.constructor(); // changed
|
||||
|
||||
for(var key in obj)
|
||||
temp[key] = clone(obj[key]);
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Capitalize first letter of document name
|
||||
* Process doc object or array of objects
|
||||
* @param {Object | Array} doc document object or array of document objects
|
||||
* @return {[type]} document object or array of document objects with capitalized first letter of document name
|
||||
*/
|
||||
function makeCap(doc){
|
||||
if(doc instanceof Array){
|
||||
for(var i=0; i<doc.length; i++){
|
||||
doc[i] = makeCap(doc[i]);
|
||||
}
|
||||
}else{
|
||||
var n = doc.name;
|
||||
doc.name = n.charAt(0).toUpperCase() + n.substring(1);
|
||||
}
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
// function populateExtra(doc, extra){
|
||||
// if(!doc.extra) doc.extra = {};
|
||||
// for(var i in extra){
|
||||
// if(!doc.extra[i]) doc.extra[i] = [];
|
||||
// doc.extra[i] = doc.extra[i].concat(extra[i]);
|
||||
// }
|
||||
// return doc;
|
||||
// }
|
||||
Reference in new issue
Block a user