2019-09-15 00:00:26 +00:00
|
|
|
const { ASContext } = require('./consts')
|
|
|
|
module.exports.validators = require('./validators');
|
|
|
|
const config = require('../config.json')
|
2019-09-13 01:03:04 +00:00
|
|
|
|
|
|
|
function isObject(value) {
|
|
|
|
return value && typeof value === 'object' && value.constructor === Object
|
|
|
|
}
|
|
|
|
// outtermost closure starts the recursion counter
|
|
|
|
// const level = 0;
|
|
|
|
function traverseObject(obj, f) {
|
|
|
|
const traverse = o => {
|
|
|
|
// const level = level + 1
|
|
|
|
// if (level > 5) return o
|
|
|
|
traverseObject(o, f)
|
|
|
|
}
|
|
|
|
if (!isObject(obj)) return obj;
|
|
|
|
Object.keys(obj).forEach(traverse)
|
|
|
|
return f(obj);
|
|
|
|
}
|
|
|
|
module.exports.toJSONLD = function (obj) {
|
2019-09-15 00:00:26 +00:00
|
|
|
obj['@context'] = obj['@context'] || ASContext;
|
2019-09-13 01:03:04 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.arrayToCollection = function (arr, ordered) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
'@context': ASContext,
|
|
|
|
totalItems: arr.length,
|
|
|
|
type: ordered ? 'orderedCollection' : 'collection',
|
|
|
|
[ordered ? 'orderedItems' : 'items']: arr,
|
|
|
|
}
|
2019-09-15 00:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.userNameToIRI = function (user) {
|
|
|
|
return `https://${config.DOMAIN}/u/${user}`
|
2019-09-13 01:03:04 +00:00
|
|
|
}
|