Skip to content

Commit

Permalink
browser entry point, improves docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tsamaya committed Jun 3, 2024
1 parent 228fa9c commit 05213b1
Show file tree
Hide file tree
Showing 35 changed files with 3,496 additions and 1,252 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
dist/
coverage/
docs/
.github/
1 change: 1 addition & 0 deletions dist/browser.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { geocode } from './geocode';
13 changes: 10 additions & 3 deletions dist/geocode.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/**
* GeocodeRequest interface
* GeocodeRequest type
*
* Represents the Request Object
*/
export type GeocodeRequest = {
/**
* a 30 character long, alphanumeric string.
* a 30 character long, alphanumeric string. The API Key is required when used in a browser. In a Node environment, it is optional, as it will be added automatically from the environment variable OPENAI_API_KEY, and a `.env` file can also be used.
*/
key?: string;
/**
Expand Down Expand Up @@ -109,7 +111,7 @@ export type GeocodeRequest = {
address_only?: number;
};
/**
*
* TODO GeocodeError
*/
export declare class GeocodeError extends Error {
response?: any;
Expand All @@ -129,6 +131,11 @@ export declare function isUndefinedOrEmpty(param: string): boolean;
* @return {Boolean} returns value
*/
export declare function isUndefinedOrNull(param: GeocodeRequest): boolean;
/**
* @private
* @param input
* @returns
*/
export declare function buildQueryString(input: any): string;
/**
* geocode address and reverse geocode coordinates using
Expand Down
2 changes: 1 addition & 1 deletion dist/opencage-api.cjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
function t(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}}),e.default=t,e}var e=/*#__PURE__*/t(require("dotenv"));function n(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(n=function(){return!!t})()}function r(){return r=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},r.apply(this,arguments)}function o(t){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},o(t)}function u(t,e){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},u(t,e)}function c(t){var e="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return function(t,e,r){if(n())return Reflect.construct.apply(null,arguments);var o=[null];o.push.apply(o,e);var c=new(t.bind.apply(t,o));return r&&u(c,r.prototype),c}(t,arguments,o(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),u(r,t)},c(t)}var i=/*#__PURE__*/function(t){function e(){for(var e,n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return(e=t.call.apply(t,[this].concat(r))||this).response=void 0,e.status=void 0,e}var n,r;return r=t,(n=e).prototype=Object.create(r.prototype),n.prototype.constructor=n,u(n,r),e}(/*#__PURE__*/c(Error));function s(t,e){var n=new i(e);return n.response={status:{code:t,message:e}},n}var a=function(t){if(t.status>=200&&t.status<300)return t;var e=new i(t.statusText);throw e.status={code:t.status,message:t.statusText},e},f=function(t){return t.json()};function p(t){return void 0===t||""===t}function l(t){return null==t}function y(t){return new Promise(function(e,n){if(l(t))n(s(400,"missing or bad query"));else{var o=function(t){var e=r({},t),n="https://api.opencagedata.com/geocode/v1/json",o=!1;return p(t.proxyURL)?(p(t.key)&&(e.key=process.env.OPENCAGE_API_KEY||process.env.OCD_API_KEY),p(e.key)&&(o=!0)):(n=t.proxyURL,delete e.proxyURL),{missingKey:o,endpoint:n,query:e}}(t);if(o.missingKey)n(s(401,"missing API key"));else{var u=o.endpoint,c=function(t){return l(t)?"":Object.keys(t).map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(t[e])}).join("&")}(o.query);!function(t,e,n){try{return fetch(t).then(a).then(f).then(function(t){e(t)}).catch(function(t){n(t)}),Promise.resolve()}catch(t){return Promise.reject(t)}}(u+"?"+c,e,n)}}})}e.config();var v={geocode:y};exports.GeocodeError=i,exports.default=v,exports.geocode=y;
function t(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}}),e.default=t,e}var e=/*#__PURE__*/t(require("dotenv"));function n(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(n=function(){return!!t})()}function r(){return r=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},r.apply(this,arguments)}function o(t){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},o(t)}function u(t,e){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},u(t,e)}function c(t){var e="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return function(t,e,r){if(n())return Reflect.construct.apply(null,arguments);var o=[null];o.push.apply(o,e);var c=new(t.bind.apply(t,o));return r&&u(c,r.prototype),c}(t,arguments,o(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),u(r,t)},c(t)}var i=/*#__PURE__*/function(t){function e(){for(var e,n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return(e=t.call.apply(t,[this].concat(r))||this).response=void 0,e.status=void 0,e}var n,r;return r=t,(n=e).prototype=Object.create(r.prototype),n.prototype.constructor=n,u(n,r),e}(/*#__PURE__*/c(Error));function s(t,e){var n=new i(e);return n.response={status:{code:t,message:e}},n}function a(t){if(t.status>=200&&t.status<300)return t;var e=new i(t.statusText);throw e.status={code:t.status,message:t.statusText},e}function f(t){return t.json()}function p(t){return void 0===t||""===t}function l(t){return null==t}function y(t){return new Promise(function(e,n){if(l(t))n(s(400,"missing or bad query"));else{var o=function(t){var e=r({},t),n="https://api.opencagedata.com/geocode/v1/json",o=!1;return p(t.proxyURL)?(p(t.key)&&(e.key=process.env.OPENCAGE_API_KEY||process.env.OCD_API_KEY),p(e.key)&&(o=!0)):(n=t.proxyURL,delete e.proxyURL),{missingKey:o,endpoint:n,query:e}}(t);if(o.missingKey)n(s(401,"missing API key"));else{var u=o.endpoint,c=function(t){return l(t)?"":Object.keys(t).map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(t[e])}).join("&")}(o.query);!function(t,e,n){try{return fetch(t).then(a).then(f).then(function(t){e(t)}).catch(function(t){n(t)}),Promise.resolve()}catch(t){return Promise.reject(t)}}(u+"?"+c,e,n)}}})}e.config();var v={geocode:y};exports.GeocodeError=i,exports.default=v,exports.geocode=y;
//# sourceMappingURL=opencage-api.cjs.map
2 changes: 1 addition & 1 deletion dist/opencage-api.cjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/opencage-api.mjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import*as t from"dotenv";function e(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(e=function(){return!!t})()}function n(){return n=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},n.apply(this,arguments)}function r(t){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},r(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function u(t){var n="function"==typeof Map?new Map:void 0;return u=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(t))return n.get(t);n.set(t,u)}function u(){return function(t,n,r){if(e())return Reflect.construct.apply(null,arguments);var u=[null];u.push.apply(u,n);var c=new(t.bind.apply(t,u));return r&&o(c,r.prototype),c}(t,arguments,r(this).constructor)}return u.prototype=Object.create(t.prototype,{constructor:{value:u,enumerable:!1,writable:!0,configurable:!0}}),o(u,t)},u(t)}var c=/*#__PURE__*/function(t){function e(){for(var e,n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return(e=t.call.apply(t,[this].concat(r))||this).response=void 0,e.status=void 0,e}var n,r;return r=t,(n=e).prototype=Object.create(r.prototype),n.prototype.constructor=n,o(n,r),e}(/*#__PURE__*/u(Error));function i(t,e){var n=new c(e);return n.response={status:{code:t,message:e}},n}var s=function(t){if(t.status>=200&&t.status<300)return t;var e=new c(t.statusText);throw e.status={code:t.status,message:t.statusText},e},a=function(t){return t.json()};function f(t){return void 0===t||""===t}function p(t){return null==t}function y(t){return new Promise(function(e,r){if(p(t))r(i(400,"missing or bad query"));else{var o=function(t){var e=n({},t),r="https://api.opencagedata.com/geocode/v1/json",o=!1;return f(t.proxyURL)?(f(t.key)&&(e.key=process.env.OPENCAGE_API_KEY||process.env.OCD_API_KEY),f(e.key)&&(o=!0)):(r=t.proxyURL,delete e.proxyURL),{missingKey:o,endpoint:r,query:e}}(t);if(o.missingKey)r(i(401,"missing API key"));else{var u=o.endpoint,c=function(t){return p(t)?"":Object.keys(t).map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(t[e])}).join("&")}(o.query);!function(t,e,n){try{return fetch(t).then(s).then(a).then(function(t){e(t)}).catch(function(t){n(t)}),Promise.resolve()}catch(t){return Promise.reject(t)}}(u+"?"+c,e,r)}}})}t.config();var l={geocode:y};export{c as GeocodeError,l as default,y as geocode};
import*as t from"dotenv";function e(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(e=function(){return!!t})()}function n(){return n=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},n.apply(this,arguments)}function r(t){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},r(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function u(t){var n="function"==typeof Map?new Map:void 0;return u=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(t))return n.get(t);n.set(t,u)}function u(){return function(t,n,r){if(e())return Reflect.construct.apply(null,arguments);var u=[null];u.push.apply(u,n);var c=new(t.bind.apply(t,u));return r&&o(c,r.prototype),c}(t,arguments,r(this).constructor)}return u.prototype=Object.create(t.prototype,{constructor:{value:u,enumerable:!1,writable:!0,configurable:!0}}),o(u,t)},u(t)}var c=/*#__PURE__*/function(t){function e(){for(var e,n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return(e=t.call.apply(t,[this].concat(r))||this).response=void 0,e.status=void 0,e}var n,r;return r=t,(n=e).prototype=Object.create(r.prototype),n.prototype.constructor=n,o(n,r),e}(/*#__PURE__*/u(Error));function i(t,e){var n=new c(e);return n.response={status:{code:t,message:e}},n}function s(t){if(t.status>=200&&t.status<300)return t;var e=new c(t.statusText);throw e.status={code:t.status,message:t.statusText},e}function a(t){return t.json()}function f(t){return void 0===t||""===t}function p(t){return null==t}function y(t){return new Promise(function(e,r){if(p(t))r(i(400,"missing or bad query"));else{var o=function(t){var e=n({},t),r="https://api.opencagedata.com/geocode/v1/json",o=!1;return f(t.proxyURL)?(f(t.key)&&(e.key=process.env.OPENCAGE_API_KEY||process.env.OCD_API_KEY),f(e.key)&&(o=!0)):(r=t.proxyURL,delete e.proxyURL),{missingKey:o,endpoint:r,query:e}}(t);if(o.missingKey)r(i(401,"missing API key"));else{var u=o.endpoint,c=function(t){return p(t)?"":Object.keys(t).map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(t[e])}).join("&")}(o.query);!function(t,e,n){try{return fetch(t).then(s).then(a).then(function(t){e(t)}).catch(function(t){n(t)}),Promise.resolve()}catch(t){return Promise.reject(t)}}(u+"?"+c,e,r)}}})}t.config();var l={geocode:y};export{c as GeocodeError,l as default,y as geocode};
//# sourceMappingURL=opencage-api.mjs.map
Loading

0 comments on commit 05213b1

Please sign in to comment.