is-xid
Version:
A unique id checker for node.js
24 lines (18 loc) • 409 B
JavaScript
/**
* Check if the given string is a XID
* @param {string} str the string to check
* @return {bool} return true if the string is a XID
*/
function isXid(str) {
if (typeof str !== 'string') {
return false;
}
if (str.length !== 20) {
return false;
}
if (Buffer.byteLength(str, 'utf8') !== 20) {
return false;
}
return true;
}
module.exports = isXid;