v1.1.2: simple merge, merge only once
This commit is contained in:
		
							vanhempi
							
								
									bf7a0ab7a3
								
							
						
					
					
						commit
						1b62407ea5
					
				
							
								
								
									
										66
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										66
									
								
								index.js
									
									
									
									
									
								
							@ -3,6 +3,58 @@
 | 
			
		||||
var certInfo = module.exports;
 | 
			
		||||
module.exports.certpem = certInfo;
 | 
			
		||||
 | 
			
		||||
// ES5 version of mergeDeep
 | 
			
		||||
// https://stackoverflow.com/questions/27936772/how-to-deep-merge-instead-of-shallow-merge
 | 
			
		||||
/**
 | 
			
		||||
 * Simple object check.
 | 
			
		||||
 * @param item
 | 
			
		||||
 * @returns {boolean}
 | 
			
		||||
 */
 | 
			
		||||
function isObject(item) {
 | 
			
		||||
  return (item && typeof item === 'object' && !Array.isArray(item));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Deep merge two objects.
 | 
			
		||||
 * @param target
 | 
			
		||||
 * @param ...sources
 | 
			
		||||
 */
 | 
			
		||||
function merge(target) {
 | 
			
		||||
  var sources = Array.prototype.slice.call(arguments);
 | 
			
		||||
  sources.shift();
 | 
			
		||||
  if (!sources.length) { return target; }
 | 
			
		||||
  var source = sources.shift();
 | 
			
		||||
  var obj;
 | 
			
		||||
 | 
			
		||||
  if (isObject(target) && isObject(source)) {
 | 
			
		||||
    Object.keys(source).forEach(function (key) {
 | 
			
		||||
      if (isObject(source[key])) {
 | 
			
		||||
        if (!target[key]) { obj = {}; obj[key] = {}; Object.assign(target, obj); }
 | 
			
		||||
        merge(target[key], source[key]);
 | 
			
		||||
      } else {
 | 
			
		||||
        obj = {}; obj[key] = source[key];
 | 
			
		||||
        Object.assign(target, obj);
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  sources.unshift(target);
 | 
			
		||||
  return merge.apply(null, sources);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var common = require("asn1js/org/pkijs/common");
 | 
			
		||||
var _asn1js = require("asn1js");
 | 
			
		||||
var _pkijs = require("pkijs");
 | 
			
		||||
var _x509schema = require("pkijs/org/pkijs/x509_schema");
 | 
			
		||||
 | 
			
		||||
// #region Merging function/object declarations for ASN1js and PKIjs
 | 
			
		||||
var asn1js = merge(_asn1js, common);
 | 
			
		||||
 | 
			
		||||
var x509schema = merge(_x509schema, asn1js);
 | 
			
		||||
 | 
			
		||||
var pkijs_1 = merge(_pkijs, asn1js);
 | 
			
		||||
var pkijs = merge(pkijs_1, x509schema);
 | 
			
		||||
 | 
			
		||||
// this is really memory expensive to do
 | 
			
		||||
// (about half of a megabyte of loaded code)
 | 
			
		||||
certInfo._pemToBinAb  = function (pem) {
 | 
			
		||||
@ -15,20 +67,6 @@ certInfo._pemToBinAb  = function (pem) {
 | 
			
		||||
};
 | 
			
		||||
certInfo.debug = certInfo.getCertInfo = function (pem) {
 | 
			
		||||
  var ab = module.exports._pemToBinAb(pem);
 | 
			
		||||
  var merge = require("node.extend");
 | 
			
		||||
 | 
			
		||||
  var common = require("asn1js/org/pkijs/common");
 | 
			
		||||
  var _asn1js = require("asn1js");
 | 
			
		||||
  var _pkijs = require("pkijs");
 | 
			
		||||
  var _x509schema = require("pkijs/org/pkijs/x509_schema");
 | 
			
		||||
 | 
			
		||||
  // #region Merging function/object declarations for ASN1js and PKIjs
 | 
			
		||||
  var asn1js = merge(true, _asn1js, common);
 | 
			
		||||
 | 
			
		||||
  var x509schema = merge(true, _x509schema, asn1js);
 | 
			
		||||
 | 
			
		||||
  var pkijs_1 = merge(true, _pkijs, asn1js);
 | 
			
		||||
  var pkijs = merge(true, pkijs_1, x509schema);
 | 
			
		||||
 | 
			
		||||
  var asn1 = pkijs.org.pkijs.fromBER(ab);
 | 
			
		||||
  var certSimpl = new pkijs.org.pkijs.simpl.CERT({ schema: asn1.result });
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,6 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "certpem",
 | 
			
		||||
  "version": "1.1.1",
 | 
			
		||||
  "version": "1.1.2",
 | 
			
		||||
  "description": "Read basic info (subject, altnames, expiresAt, issuedAt) from a cert.pem / x509 certificate (tls / ssl / https) ",
 | 
			
		||||
  "main": "index.js",
 | 
			
		||||
  "bin": {
 | 
			
		||||
@ -39,9 +39,6 @@
 | 
			
		||||
  "homepage": "https://git.coolaj86.com/coolaj86/cert-info.js",
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
    "asn1js": "^1.2.12",
 | 
			
		||||
    "node.extend": "^1.1.6",
 | 
			
		||||
    "pkijs": "^1.3.27"
 | 
			
		||||
  },
 | 
			
		||||
  "trulyOptionalDependencies": {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Ladataan…
	
	
			
			x
			
			
		
	
		Viittaa uudesa ongelmassa
	
	Block a user