xonecas.io
311
Fn

ffmpeg-node / files

ffmpeg-node / helpers.js

739 bytes
1/*
2* @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
3* @example
4* objectToArray({'-vpre': ['slow', 'baseline'], '-vcodec': 'libx264'})
5* returns ['-vpre','slow','-vpre','baseline','-vcodec','libx264']
6* @param {Object} obj
7* @returns {Array} arr
8*/
9
10var objectToArray =  exports.objectToArray = function (obj) {
11	var arr = [], key;
12	
13	for (key in obj) {
14		var objectValue = obj[key];
15		if(objectValue instanceof Array) {
16			objectValue.forEach(function (elm, i) {
17				arr.push(key, elm);
18			});
19		} else {
20			arr.push(key, objectValue);
21		}
22	}
23
24	return arr;
25};