Skip to content

Instantly share code, notes, and snippets.

@1Conan
Created January 3, 2018 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1Conan/e1b140f20bb9ec1601ee50e24b8c2a21 to your computer and use it in GitHub Desktop.
Save 1Conan/e1b140f20bb9ec1601ee50e24b8c2a21 to your computer and use it in GitHub Desktop.
const isHex = require('is-hex')
const converter = require('hex2dec')
module.exports = (ecid, ecidType) => {
if(ecidType == 'dec')
return validateDecEcid(ecid)
else if(ecidType == 'hex')
return validateHexEcid(ecid)
else
return false
}
function validateHexEcid(ecid) {
if(!isHex(ecid)) return false
if(!ecid.startsWith('0x')) return `0x${ecid}`
return ecid
}
function validateDecEcid(ecid) {
if(!/[0-9]+/g.test(ecid)) return false
return converter.decToHex(ecid)
}
const ecidLength = {
"iPhone8,1": 13
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment