Created
January 3, 2018 00:40
-
-
Save 1Conan/e1b140f20bb9ec1601ee50e24b8c2a21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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