Nodejs String to Byte Convert getBytes()

Here you can find the source of getBytes()

Method Source Code

String.prototype.getBytes = function() {   
      var cArr = this.match(/[^\x00-\xff]/ig);   
      return this.length + (cArr == null ? 0 : cArr.length*2);   
  }/*from   ww w  .j  av  a2s .  c  o  m*/

Related

  1. getBytes()
    String.prototype.getBytes = function () {
        var bytes = [];
        for (var i = 0; i < this.length; i++) {
            bytes.push(this.charCodeAt(i));
        return bytes;
    };
    
  2. getBytes()
    function addAll(arr1, arr2) {
      var i=0;
      for(i=0;i<arr2.length;i++) {
        arr1.push(arr2[i]);
    String.prototype.getBytes = function() {
        return encodeURIComponent(this).replace(/%../g, 'x').length;
    };
    ...
    
  3. getBytes()
    var crypto = require('crypto')
    String.prototype.getBytes = function () {
      var bytes = [];
      for (var i = 0; i < this.length; ++i) {
        bytes.push(this.charCodeAt(i));
      return bytes;
    };
    module.exports = function convert(secretKey) {
    ...
    
  4. toByteString()
    String.prototype.toByteString = function()
       var ar = this.split(' '),
         res = "";
       for(var i = 0; i < ar.length; ++i)
        res += String.fromCharCode( parseInt(ar[i], 16) );
       return res;
    ...