Skip to content

Commit

Permalink
feat(tools): arrToStr function
Browse files Browse the repository at this point in the history
extract single string from array
  • Loading branch information
drawnepicenter committed Aug 11, 2016
1 parent af53971 commit 1f5ea44
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ exports.checkConfig = (file) => {
return true
}

/**
* Checks if object is a single string in an array
* @public
* @param {Object} obj Any object
* @return {Object} Original object or extracted string
*/
exports.arrToStr = (obj) => {
let fixed = null
if (Array.isArray(obj) && obj.length === 1 && typeof obj[0] === 'string') {
fixed = obj[0]
} else {
fixed = obj
}
return fixed
}

/**
* Handles data export to file. Supports cson, json, noon, plist, xml, yaml.
* @public
Expand Down

0 comments on commit 1f5ea44

Please sign in to comment.