Skip to content

Latest commit

 

History

History
47 lines (33 loc) · 1.06 KB

nodejs_tips.md

File metadata and controls

47 lines (33 loc) · 1.06 KB

Node JS tips

base64 and md5

var crypto = require('crypto');
var md5 = crypto.createHash('md5');
var m = md5.update( Buffer.from( data , 'binary' )  ).digest('hex');
console.log( m  , data.length ) ;

let b64 = Buffer.from( data , 'binary' ).toString('base64')
let unb64 = Buffer.from("SGVsbG8gV29ybGQ=", 'base64').toString('binary') ? or 'ascii' ?

string format

// First, checks if it isn't implemented yet.
if (!String.prototype.format) {
  String.prototype.format = function() {
    var args = arguments;
    return this.replace(/{(\d+)}/g, function(match, number) { 
      return typeof args[number] != 'undefined'
        ? args[number]
        : match
      ;
    });
  };
}