-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.brreg.min.js
19 lines (19 loc) · 2.41 KB
/
jquery.brreg.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
* jQuery Plugin: bbreg Plugin (Norwegian Company lookups)
* https://github.com/gitleif/brregPlugin/
*
* Copyright (c) 2018, Leif Nesheim and Systemsmia DA http://www.systemsmia.no/
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* Usage:
* getCompanies(request, callback) -> Returns to callback all companys matching request
* getCompany(organizationid, callback) -> Get all registered information about one single company, defined by organizationid
* getCompanyEHF(organizationid, callback) -> Get EHF information about one single comapny, defined by organizationid
*
*
* Author: leifnesheim@hotmail.com
* Version: 1.0
* Date: 02/11/2018
*/
(function(){if(!String.prototype.startsWith){String.prototype.startsWith=function(e,d){d=d||0;return this.indexOf(e,d)===d;};}this.brregPlugin=function(){var d={size:30,filter:"%req%"};if(typeof arguments[0]!=="undefined"){if(arguments[0]&&typeof arguments[0]==="object"){this.options=b(d,arguments[0]);}}else{this.options=d;}this.getCompanies=function(h,f){var e=("?navn="+this.options.filter.replace("%req%",encodeURIComponent(h))+"&size="+this.options.size);var g=$.getJSON("https://data.brreg.no/enhetsregisteret/api/enheter"+e,function(l){var m=[];if(typeof l._embedded!=="undefined"){for(var k=0;k<l._embedded.enheter.length;k++){var j=l._embedded.enheter[k];if(j.underAvvikling==false&&j.navn.startsWith(h.toUpperCase())){m.push({label:c(j.navn),id:j.organisasjonsnummer});}}}f(m);});};this.getCompany=function(g,e){var f=$.getJSON("https://data.brreg.no/enhetsregisteret/api/enheter/"+encodeURIComponent(g),function(h){if(h!=null||h!=="undefined"){h.navn=c(h.navn);if(h.forretningsadresse===null||h.forretningsadresse==="undefined"){h.forretningsadresse={adresse:null,kommune:null,kommunenummer:null,land:null,landkode:null,postnummer:null,poststed:null};}e(h);}else{e(null);}});};this.getCompanyEHF=function(f,e){if(f.toString().length==9&&isNaN(parseFloat(f))==false){$.getJSON("https://hotell.difi.no/api/json/difi/elma/participants?PEPPOLBIS_3_0_BILLING_01_UBL=Ja&query="+encodeURIComponent(f),function(g){e((b({ehf_invoice_2:false,ehf_creditnote_2:false},g.entries[0])));return true;});}};};function b(f,d){var e;for(e in d){if(d.hasOwnProperty(e)){f[e]=d[e];}}return f;}function a(d){return(d.toLowerCase().split(" ").map(function(e){return e.charAt(0).toUpperCase()+e.substring(1);}).join(" "));}function c(d){return(decodeURI(a(d)));}}());