diff --git a/README.md b/README.md index a024179..7bd6bea 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ The purpose of this repo is to create a single point of access for all those lit ### Structure -The structure is super simple, there is a master import at the root of src that pulls in the namespaces, those in turn have their own indeci which import the modules themselves. +The structure is super simple, there is a master import at the root of src that pulls in the namespaces, those in turn have their own indice which import the modules themselves. -Each module is a sinlge exported function, please continue this way as it makes things easy to reason about and keeps individual modules small. +Each module is a single exported function, please continue this way as it makes things easy to reason about and keeps individual modules small. The aim with this approach is to have small files that do one thing well. diff --git a/cypress.json b/cypress.json deleted file mode 100644 index 0967ef4..0000000 --- a/cypress.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json deleted file mode 100644 index da18d93..0000000 --- a/cypress/fixtures/example.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Using fixtures to represent data", - "email": "hello@cypress.io", - "body": "Fixtures are a great way to mock data for responses to routes" -} \ No newline at end of file diff --git a/cypress/integration/getIndex.js b/cypress/integration/getIndex.js deleted file mode 100644 index 9596987..0000000 --- a/cypress/integration/getIndex.js +++ /dev/null @@ -1,9 +0,0 @@ -import getIndex from '../../src/vanilla/getIndex'; - -describe('Modules', function(){ - - it('Can correctly run getIndex and return the desired object index', function() { - const arr = [{ testA: 1, testB: 2 }, { testA: 3, testB: 4 }] - expect(getIndex(arr, 'testA', 3)).to.eq(1) - }) -}) diff --git a/cypress/integration/getObject.js b/cypress/integration/getObject.js deleted file mode 100644 index 004a35d..0000000 --- a/cypress/integration/getObject.js +++ /dev/null @@ -1,9 +0,0 @@ -import getObject from '../../src/vanilla/getObject'; - -describe('Modules', function(){ - - it('Can correctly run getObject and return the desired object', function() { - const arr = [{ testA: 1, testB: 2 }, { testA: 3, testB: 4 }] - expect(getObject(arr, 'testA', 3)).to.eq(arr[1]) - }) -}) diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js deleted file mode 100644 index fd170fb..0000000 --- a/cypress/plugins/index.js +++ /dev/null @@ -1,17 +0,0 @@ -// *********************************************************** -// This example plugins/index.js can be used to load plugins -// -// You can change the location of this file or turn off loading -// the plugins file with the 'pluginsFile' configuration option. -// -// You can read more here: -// https://on.cypress.io/plugins-guide -// *********************************************************** - -// This function is called when a project is opened or re-opened (e.g. due to -// the project's config changing) - -module.exports = (on, config) => { - // `on` is used to hook into various events Cypress emits - // `config` is the resolved Cypress config -} diff --git a/cypress/support/commands.js b/cypress/support/commands.js deleted file mode 100644 index ca4d256..0000000 --- a/cypress/support/commands.js +++ /dev/null @@ -1,25 +0,0 @@ -// *********************************************** -// This example commands.js shows you how to -// create various custom commands and overwrite -// existing commands. -// -// For more comprehensive examples of custom -// commands please read more here: -// https://on.cypress.io/custom-commands -// *********************************************** -// -// -// -- This is a parent command -- -// Cypress.Commands.add("login", (email, password) => { ... }) -// -// -// -- This is a child command -- -// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... }) -// -// -// -- This is a dual command -- -// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... }) -// -// -// -- This will overwrite an existing command -- -// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) diff --git a/cypress/support/index.js b/cypress/support/index.js deleted file mode 100644 index d68db96..0000000 --- a/cypress/support/index.js +++ /dev/null @@ -1,20 +0,0 @@ -// *********************************************************** -// This example support/index.js is processed and -// loaded automatically before your test files. -// -// This is a great place to put global configuration and -// behavior that modifies Cypress. -// -// You can change the location of this file or turn off -// automatically serving support files with the -// 'supportFile' configuration option. -// -// You can read more here: -// https://on.cypress.io/configuration -// *********************************************************** - -// Import commands.js using ES2015 syntax: -import './commands' - -// Alternatively you can use CommonJS syntax: -// require('./commands') diff --git a/package.json b/package.json index c91c116..617c539 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@neuekit/utilities", - "version": "1.6.0", + "version": "1.7.0", "license": "MIT", "description": "Tree-shakeable JavaScript utilities, add yours today!", "main": "dist/bundle.js", @@ -18,34 +18,31 @@ "access": "public" }, "dependencies": { - "dayjs": "^1.8.27", + "dayjs": "^1.9.6", "qss": "^2.0.3" }, "devDependencies": { - "@babel/core": "^7.10.5", - "@babel/preset-env": "^7.9.6", - "@rollup/plugin-babel": "^5.0.0", - "@rollup/plugin-commonjs": "^11.1.0", - "@rollup/plugin-node-resolve": "^7.1.3", - "@rollup/plugin-replace": "^2.3.2", - "cypress": "^4.5.0", - "documentation": "^13.0.0", + "@babel/core": "^7.12.3", + "@babel/preset-env": "^7.12.1", + "@rollup/plugin-babel": "^5.2.1", + "@rollup/plugin-commonjs": "^16.0.0", + "@rollup/plugin-node-resolve": "^10.0.0", + "@rollup/plugin-replace": "^2.3.4", + "documentation": "^13.1.0", "dotenv": "^8.2.0", "npm-run-all": "^4.1.5", - "onchange": "^7.0.2", - "prettier": "^2.0.5", - "rollup": "^2.10.2", - "rollup-plugin-terser": "^5.3.0" + "onchange": "^7.1.0", + "prettier": "^2.1.2", + "rollup": "^2.33.2", + "rollup-plugin-terser": "^7.0.2" }, "scripts": { "build": "rollup --config", "dev": "rollup --config --watch", - "cypress": "cypress open", "prettier": "prettier --config --write ./src/**/*.js", "documentation": "documentation build ./src/** -f md -o docs/index.md", "watch:prettier": "onchange './src/**/*.js' -- npm run prettier", "watch:documentation": "onchange './src/**/*.js' -- npm run documentation", - "watch": "run-p 'watch:prettier' 'watch:documentation'", - "test": "npm run cypress" + "watch": "run-p 'watch:prettier' 'watch:documentation'" } } diff --git a/src/integrations/googlemaps.js b/src/integrations/googlemaps.js index 36da22e..349b4d7 100644 --- a/src/integrations/googlemaps.js +++ b/src/integrations/googlemaps.js @@ -1,7 +1,5 @@ -/** - * @private - */ -let googleMapsScriptIsInjected = false; +import createEl from '../vanilla/createEl'; +import { encode } from 'qss'; /** * Allows for programmatic insertion of Google Maps script @@ -10,24 +8,17 @@ let googleMapsScriptIsInjected = false; * @param {object} options the Google Maps Api params */ export default function (options = {}) { - if (googleMapsScriptIsInjected) { + if (document.getElementById('neuekitGoogle')) { window[options.callback](); return; } - - const optionsQuery = Object.keys(options) - .map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(options[k])}`) - .join('&'); - - const url = `https://maps.googleapis.com/maps/api/js?${optionsQuery}`; - - const script = document.createElement('script'); - - script.setAttribute('src', url); - script.setAttribute('async', ''); - script.setAttribute('defer', ''); + + const script = createEl('script', { + src: 'https://maps.googleapis.com/maps/api/js?' + encode(options), + id: 'neuekitGoogle', + async: '', + defer: '' + }); document.head.appendChild(script); - - googleMapsScriptIsInjected = true; } diff --git a/src/vanilla/createEl.js b/src/vanilla/createEl.js new file mode 100644 index 0000000..d3c5eff --- /dev/null +++ b/src/vanilla/createEl.js @@ -0,0 +1,19 @@ + /** + * Creates an element with a given object of attributes + * @memberof Vanilla + * @version 1.0.0 + * @param {string} name of the element such as 'div' + * @param {object} key/value object of attribute names and values + * @returns {node} returns node + */ + +export default function (tagName, attributes = {}) { + + const elem = document.createElement(tagName); + + for (const key in attributes) { + elem[key] = attributes[key]; + } + + return elem; +}; \ No newline at end of file diff --git a/src/vanilla/index.js b/src/vanilla/index.js index 0a57fc6..cf22ecf 100644 --- a/src/vanilla/index.js +++ b/src/vanilla/index.js @@ -1,4 +1,5 @@ import copy from './copy'; +import createEl from './createEl'; import getIndex from './getIndex'; import getObject from './getObject'; import hex from './hex'; @@ -17,6 +18,7 @@ import titleCase from './titleCase'; export { copy, + createEl, getIndex, getObject, hex,