Skip to content

Commit

Permalink
remove cypress and add createEl plus update googlemaps
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt authored and Matt committed Nov 16, 2020
1 parent ed81fbe commit 2ee01b6
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 124 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 0 additions & 1 deletion cypress.json

This file was deleted.

5 changes: 0 additions & 5 deletions cypress/fixtures/example.json

This file was deleted.

9 changes: 0 additions & 9 deletions cypress/integration/getIndex.js

This file was deleted.

9 changes: 0 additions & 9 deletions cypress/integration/getObject.js

This file was deleted.

17 changes: 0 additions & 17 deletions cypress/plugins/index.js

This file was deleted.

25 changes: 0 additions & 25 deletions cypress/support/commands.js

This file was deleted.

20 changes: 0 additions & 20 deletions cypress/support/index.js

This file was deleted.

31 changes: 14 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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'"
}
}
29 changes: 10 additions & 19 deletions src/integrations/googlemaps.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
19 changes: 19 additions & 0 deletions src/vanilla/createEl.js
Original file line number Diff line number Diff line change
@@ -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;
};
2 changes: 2 additions & 0 deletions src/vanilla/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy from './copy';
import createEl from './createEl';
import getIndex from './getIndex';
import getObject from './getObject';
import hex from './hex';
Expand All @@ -17,6 +18,7 @@ import titleCase from './titleCase';

export {
copy,
createEl,
getIndex,
getObject,
hex,
Expand Down

0 comments on commit 2ee01b6

Please sign in to comment.