-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathhelpers.js
More file actions
25 lines (22 loc) · 739 Bytes
/
helpers.js
File metadata and controls
25 lines (22 loc) · 739 Bytes
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
/*
* @description Converts an object without nested object properties e.g. {'-key1': 'String1', '-key2': 'String2'} into an array like ['-key1','-String1','-key2','-String2']. If you need a key twice put the values into an array
* @example
* objectToArray({'-vpre': ['slow', 'baseline'], '-vcodec': 'libx264'})
* returns ['-vpre','slow','-vpre','baseline','-vcodec','libx264']
* @param {Object} obj
* @returns {Array} arr
*/
var objectToArray = exports.objectToArray = function (obj) {
var arr = [], key;
for (key in obj) {
var objectValue = obj[key];
if(objectValue instanceof Array) {
objectValue.forEach(function (elm, i) {
arr.push(key, elm);
});
} else {
arr.push(key, objectValue);
}
}
return arr;
};