You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
598 B
22 lines
598 B
2 years ago
|
var utf8 = require('./utf8');
|
||
|
var hex = require('./hex');
|
||
|
var base64 = require('./base64');
|
||
|
exports = function(str) {
|
||
|
var encoding =
|
||
|
arguments.length > 1 && arguments[1] !== undefined
|
||
|
? arguments[1]
|
||
|
: 'utf8';
|
||
|
if (encoding === 'hex') return hex.decode(str);
|
||
|
if (encoding === 'base64') return base64.decode(str);
|
||
|
var bytes = [];
|
||
|
if (encoding === 'utf8') {
|
||
|
str = utf8.encode(str);
|
||
|
}
|
||
|
for (var i = 0, len = str.length; i < len; i++) {
|
||
|
bytes.push(str.charCodeAt(i) & 0xff);
|
||
|
}
|
||
|
return bytes;
|
||
|
};
|
||
|
|
||
|
module.exports = exports;
|