load-google-maps-api
Advanced tools
Comparing version 0.0.2 to 0.0.3
18
index.js
@@ -6,4 +6,5 @@ export default ({ | ||
libraries = [], | ||
region, | ||
timeout = 10000, | ||
v, | ||
v | ||
} = {}) => { | ||
@@ -22,10 +23,11 @@ | ||
const scriptElement = document.createElement('script'); | ||
const params = ['callback=' + callbackName]; | ||
if (client) params.push('client=' + client); | ||
if (key) params.push('key=' + key); | ||
if (language) params.push('language=' + language); | ||
const params = [`callback=${callbackName}`]; | ||
if (client) params.push(`client=${client}`); | ||
if (key) params.push(`key=${key}`); | ||
if (language) params.push(`language=${language}`); | ||
libraries = [].concat(libraries); // Ensure that `libraries` is an array | ||
if (libraries.length) params.push('libraries=' + libraries.join(',')); | ||
if (v) params.push('v=' + v); | ||
scriptElement.src = 'https://maps.googleapis.com/maps/api/js?' + params.join('&'); | ||
if (libraries.length) params.push(`libraries=${libraries.join(',')}`); | ||
if (region) params.push(`region=${region}`); | ||
if (v) params.push(`v=${v}`); | ||
scriptElement.src = `https://maps.googleapis.com/maps/api/js?${params.join('&')}`; | ||
@@ -32,0 +34,0 @@ // Timeout if necessary. |
@@ -8,13 +8,13 @@ 'use strict'; | ||
exports.default = function () { | ||
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
client = _ref.client, | ||
key = _ref.key, | ||
language = _ref.language, | ||
_ref$libraries = _ref.libraries, | ||
libraries = _ref$libraries === undefined ? [] : _ref$libraries, | ||
region = _ref.region, | ||
_ref$timeout = _ref.timeout, | ||
timeout = _ref$timeout === undefined ? 10000 : _ref$timeout, | ||
v = _ref.v; | ||
var client = _ref.client; | ||
var key = _ref.key; | ||
var language = _ref.language; | ||
var _ref$libraries = _ref.libraries; | ||
var libraries = _ref$libraries === undefined ? [] : _ref$libraries; | ||
var _ref$timeout = _ref.timeout; | ||
var timeout = _ref$timeout === undefined ? 10000 : _ref$timeout; | ||
var v = _ref.v; | ||
var callbackName = '__googleMapsApiOnLoadCallback'; | ||
@@ -37,2 +37,3 @@ | ||
if (libraries.length) params.push('libraries=' + libraries.join(',')); | ||
if (region) params.push('region=' + region); | ||
if (v) params.push('v=' + v); | ||
@@ -39,0 +40,0 @@ scriptElement.src = 'https://maps.googleapis.com/maps/api/js?' + params.join('&'); |
{ | ||
"name": "load-google-maps-api", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A thin, Promise-returning helper for loading the Google Maps JavaScript API.", | ||
@@ -5,0 +5,0 @@ "author": "Lim Yuan Qing", |
@@ -42,3 +42,3 @@ # load-google-maps-api [![npm Version](http://img.shields.io/npm/v/load-google-maps-api.svg?style=flat)](https://www.npmjs.com/package/load-google-maps-api) [![Build Status](https://img.shields.io/travis/yuanqing/load-google-maps-api.svg?branch=master&style=flat)](https://travis-ci.org/yuanqing/load-google-maps-api) | ||
### loadGoogleMapsAPI([opts]) | ||
### loadGoogleMapsAPI([options]) | ||
@@ -48,5 +48,5 @@ Returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). (See [Usage](#usage).) | ||
- **Fulfilled** if load was successful. The fulfilled callback is passed the `google.maps` object. | ||
- **Rejected** if we weren’t able to load the Google Maps API after `opts.timeout`. | ||
- **Rejected** if we weren’t able to load the Google Maps API after `options.timeout`. | ||
`opts` is an optional object literal: | ||
`options` is an optional object literal: | ||
@@ -57,4 +57,5 @@ Key | Description | Default | ||
`key` | [Your API key](https://developers.google.com/maps/documentation/javascript/get-api-key#specify-a-key-when-loading-the-api) | `undefined` | ||
`language` | [Language](https://developers.google.com/maps/documentation/javascript/examples/map-rtl) | `undefined` | ||
`language` | [Language](https://developers.google.com/maps/documentation/javascript/localization#Language) | `undefined` | ||
`libraries` | [Supplemental libraries to load](https://developers.google.com/maps/documentation/javascript/libraries) | `[]` | ||
`region` | [Region](https://developers.google.com/maps/documentation/javascript/localization#Region) | `undefined` | ||
`timeout` | Time in milliseconds before rejecting the promise | `10000` | ||
@@ -68,3 +69,3 @@ `v` | [API version](https://developers.google.com/maps/documentation/javascript/versions) | `undefined` | ||
``` | ||
$ npm i --save load-google-maps-api | ||
$ npm install --save load-google-maps-api | ||
``` | ||
@@ -71,0 +72,0 @@ |
11403
144
72