diff --git a/lib/resin/device/device.coffee b/lib/resin/device/device.coffee index 4a55c4b6..9d94205d 100644 --- a/lib/resin/device/device.coffee +++ b/lib/resin/device/device.coffee @@ -3,6 +3,17 @@ _ = require('lodash') # TODO: This should be fetch from the server DEVICES = require('./device-data.json') +# Get display name for a device +# +# For a list of supported devices, see getSupportedDevices() +# +# @param {String} device device name +# @return {String} device display name or 'Unknown' +# +# @example Get display name +# console.log resin.device.getDisplayName('raspberry-pi') # Raspberry Pi +# console.log resin.device.getDisplayName('rpi') # Raspberry Pi +# exports.getDisplayName = (device) -> if _.indexOf(exports.getSupportedDevices(), device) isnt -1 return device @@ -12,9 +23,25 @@ exports.getDisplayName = (device) -> return key return 'Unknown' +# Get device slug +# +# @param {String} device device name +# @return {String} device slug or 'unknown' +# +# @example Get device slug +# console.log resin.device.getDeviceSlug('Raspberry Pi') # raspberry-pi +# exports.getDeviceSlug = (device) -> displayName = exports.getDisplayName(device) return DEVICES[displayName]?.slug or 'unknown' +# Get a list of supported devices +# +# @return {Array} a list of all supported devices, by their display names +# +# @example Get all supported devices +# devices = resin.device.getSupportedDevices() +# console.log(devices) +# exports.getSupportedDevices = -> return _.keys(DEVICES)