-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.js
48 lines (44 loc) · 1.35 KB
/
metadata.js
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
//var helpers = require('./helpers');
// TODO this is copy-pasted function from './helpers' to avoid dependency.
function cloneAndUpdate(obj, updates) {
if (obj.path) {
// that's how it was done previously:
// var clone = obj.clone();
//
// but we can't use vinyl's clone method because
// vinyl's clone is deep
// (painfully slow and unecessary in this case)
// so we create new vinyl File instead
var clone = {
path: obj.path,
contents: obj.contents,
}
return Object.assign(clone, obj, updates);
}
return Object.assign({}, obj, updates);
}
//------------------------------------
function getMetadata(file) {
return file.metadata || [];
}
module.exports = {
from: function (obj) {
return Object.assign({}, obj);
},
findMetadata: function (file, params) {
},
getMetadata: getMetadata,
addMetadata: function addMetadata(file, metadataToAdd) {
var previousMetadata = file.metadata || [];
return cloneAndUpdate(file, {
metadata: previousMetadata.concat(
metadataToAdd.map(entry => Object.assign(
{},
entry,
{type: entry.type || entry.name},
{file: file}
))
)
});
}
}