UNPKG

electron-updater

Version:

Cross platform auto-updater for electron applications

46 lines (40 loc) 1.29 kB
/* This module contains helpers for appdirectory * * instanceOf(object, constructor) * - determines if an object is an instance of * a constructor * - ignores distinction between objects and * literals - converts all literals into * their object counterparts * - returns a boolean */ var instanceOf = function(object, constructor) { // If object is a string/array/number literal, // turn it into a 'real' object if (typeof object != "object") { object = new object.constructor(object) } // Iterate up the object's prototype chain while (object != null) { if (object == constructor.prototype) { // We've found the correct prototype! return true } // Next prototype up object = Object.getPrototypeOf(object) } // Nothing found. return false } var formatStr = function(format) { // This function has been stolen liberally from // http://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format var args = Array.prototype.slice.call(arguments, 1) return format.replace(/{(\d+)}/g, function(match, number) { return typeof args[number] != 'undefined' ? args[number] : match }) } module.exports.instanceOf = instanceOf module.exports.formatStr= formatStr