@pernod-ricard-global-cms/jsutils 1.2.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/npm-publish.yml +34 -0
- package/jsutils.js +37 -26
- package/package.json +6 -2
- package/spec/isEmailValid.spec.js +10 -0
- package/spec/isInViewport.spec.js +7 -0
- package/spec/support/jasmine.json +12 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# This workflow will run tests using node and then publish a package to NPM when a release is created
|
|
2
|
+
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
|
|
3
|
+
|
|
4
|
+
name: Node.js Package
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
release:
|
|
8
|
+
types: [created]
|
|
9
|
+
branches:
|
|
10
|
+
- master
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v2
|
|
17
|
+
- uses: actions/setup-node@v2
|
|
18
|
+
with:
|
|
19
|
+
node-version: 15
|
|
20
|
+
- run: npm ci
|
|
21
|
+
|
|
22
|
+
publish-npm:
|
|
23
|
+
needs: build
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
steps:
|
|
26
|
+
- uses: actions/checkout@v2
|
|
27
|
+
- uses: actions/setup-node@v2
|
|
28
|
+
with:
|
|
29
|
+
node-version: 14
|
|
30
|
+
registry-url: https://registry.npmjs.org/
|
|
31
|
+
- run: npm ci
|
|
32
|
+
- run: npm publish
|
|
33
|
+
env:
|
|
34
|
+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
package/jsutils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable no-undef */
|
|
2
2
|
/* eslint-disable consistent-return */
|
|
3
3
|
/* eslint-disable no-console */
|
|
4
|
-
function getPosition( element ) {
|
|
4
|
+
export function getPosition( element ) {
|
|
5
5
|
const scrollElementTag = document.scrollingElement.tagName;
|
|
6
6
|
let xPosition = 0;
|
|
7
7
|
let yPosition = 0;
|
|
@@ -18,7 +18,7 @@ function getPosition( element ) {
|
|
|
18
18
|
return { x: xPosition, y: yPosition };
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function toggleClassByValidity( input, button ) {
|
|
21
|
+
export function toggleClassByValidity( input, button ) {
|
|
22
22
|
input.addEventListener( 'input', () => {
|
|
23
23
|
if ( input.validity.valid && input.value ) {
|
|
24
24
|
if ( ! button.classList.contains( 'valid' ) ) {
|
|
@@ -34,7 +34,7 @@ function toggleClassByValidity( input, button ) {
|
|
|
34
34
|
} );
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
function inCriticalCssConfig( assetKey ) {
|
|
37
|
+
export function inCriticalCssConfig( assetKey ) {
|
|
38
38
|
if (
|
|
39
39
|
globalThis.criticalConfig &&
|
|
40
40
|
globalThis.criticalConfig.indexOf( assetKey ) === -1
|
|
@@ -44,7 +44,7 @@ function inCriticalCssConfig( assetKey ) {
|
|
|
44
44
|
return true;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
function loadCss( assetKey, options = { css: true } ) {
|
|
47
|
+
export function loadCss( assetKey, options = { css: true } ) {
|
|
48
48
|
const promise = new Promise( ( resolve ) => {
|
|
49
49
|
if ( options.css === true && ! inCriticalCssConfig( assetKey ) ) {
|
|
50
50
|
import(
|
|
@@ -57,7 +57,7 @@ function loadCss( assetKey, options = { css: true } ) {
|
|
|
57
57
|
return promise;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
function checkDevice() {
|
|
60
|
+
export function checkDevice() {
|
|
61
61
|
try {
|
|
62
62
|
const deviceAgent = navigator.userAgent.toLowerCase();
|
|
63
63
|
const htmlElement = document.querySelector( 'html' );
|
|
@@ -112,7 +112,7 @@ function checkDevice() {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
async function waitForLoad( img, delayedFunction ) {
|
|
115
|
+
export async function waitForLoad( img, delayedFunction ) {
|
|
116
116
|
const loaded = new Promise( ( resolve ) => {
|
|
117
117
|
if ( img.complete ) {
|
|
118
118
|
if ( typeof delayedFunction === 'function' ) {
|
|
@@ -136,7 +136,7 @@ async function waitForLoad( img, delayedFunction ) {
|
|
|
136
136
|
return loaded;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
async function supportsWebp() {
|
|
139
|
+
export async function supportsWebp() {
|
|
140
140
|
// eslint-disable-next-line no-restricted-globals
|
|
141
141
|
if ( ! self.createImageBitmap ) return false;
|
|
142
142
|
const webpData =
|
|
@@ -154,7 +154,7 @@ async function supportsWebp() {
|
|
|
154
154
|
// return false;
|
|
155
155
|
// } )();
|
|
156
156
|
|
|
157
|
-
function footerIntersection( entries, element ) {
|
|
157
|
+
export function footerIntersection( entries, element ) {
|
|
158
158
|
entries.forEach( ( entry ) => {
|
|
159
159
|
if ( element ) {
|
|
160
160
|
if ( entry.isIntersecting ) {
|
|
@@ -167,10 +167,10 @@ function footerIntersection( entries, element ) {
|
|
|
167
167
|
} );
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
function getSwiperAssets() {
|
|
170
|
+
export function getSwiperAssets() {
|
|
171
171
|
const getSwiperJs = () =>
|
|
172
172
|
import(
|
|
173
|
-
/* webpackChunkName: 'swiper' */ '../../swiper/swiper-bundle'
|
|
173
|
+
/* webpackChunkName: 'swiper' */ '../../swiper/swiper-bundle.js'
|
|
174
174
|
);
|
|
175
175
|
|
|
176
176
|
const getSwiperCss = () =>
|
|
@@ -187,26 +187,26 @@ function getSwiperAssets() {
|
|
|
187
187
|
return promisedJs;
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
function getJquery() {
|
|
190
|
+
export function getJquery() {
|
|
191
191
|
if ( ! window.jQuery ) {
|
|
192
192
|
const importCode = () =>
|
|
193
193
|
import(
|
|
194
|
-
/* webpackChunkName: 'jquery' */ '../../jquery/dist/jquery.min'
|
|
194
|
+
/* webpackChunkName: 'jquery' */ '../../jquery/dist/jquery.min.js'
|
|
195
195
|
);
|
|
196
196
|
return importCode();
|
|
197
197
|
}
|
|
198
198
|
return Promise.resolve();
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
function getGsap() {
|
|
201
|
+
export function getGsap() {
|
|
202
202
|
const gsapCore = () =>
|
|
203
|
-
import( '../../gsap/dist/gsap.min' ).then( ( gsapObj ) => {
|
|
203
|
+
import( '../../gsap/dist/gsap.min.js' ).then( ( gsapObj ) => {
|
|
204
204
|
const { gsap } = gsapObj;
|
|
205
205
|
return gsap;
|
|
206
206
|
} );
|
|
207
207
|
|
|
208
208
|
const gsapPlugin = () =>
|
|
209
|
-
import( '../../gsap/dist/ScrollTrigger.min' ).then(
|
|
209
|
+
import( '../../gsap/dist/ScrollTrigger.min.js' ).then(
|
|
210
210
|
( scrollObj ) => {
|
|
211
211
|
const ScrollTrigger = scrollObj;
|
|
212
212
|
return ScrollTrigger;
|
|
@@ -221,19 +221,19 @@ function getGsap() {
|
|
|
221
221
|
return prom;
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
function isTablet( userAgent ) {
|
|
224
|
+
export function isTablet( userAgent ) {
|
|
225
225
|
return /(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(
|
|
226
226
|
userAgent.toLowerCase()
|
|
227
227
|
);
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
-
function mobileCheck () {
|
|
230
|
+
export function mobileCheck () {
|
|
231
231
|
let check = false;
|
|
232
232
|
(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera);
|
|
233
233
|
return check;
|
|
234
234
|
};
|
|
235
235
|
|
|
236
|
-
function resizeDebouncer( debouncedFunction, time = 250 ) {
|
|
236
|
+
export function resizeDebouncer( debouncedFunction, time = 250 ) {
|
|
237
237
|
let resizeTimer;
|
|
238
238
|
window.addEventListener( 'resize', () => {
|
|
239
239
|
clearTimeout( resizeTimer );
|
|
@@ -242,7 +242,8 @@ function resizeDebouncer( debouncedFunction, time = 250 ) {
|
|
|
242
242
|
}, time );
|
|
243
243
|
} );
|
|
244
244
|
}
|
|
245
|
-
|
|
245
|
+
|
|
246
|
+
export function eventListenerDebouncer(
|
|
246
247
|
element,
|
|
247
248
|
eventType,
|
|
248
249
|
debouncedFunction,
|
|
@@ -257,7 +258,7 @@ function eventListenerDebouncer(
|
|
|
257
258
|
} );
|
|
258
259
|
}
|
|
259
260
|
|
|
260
|
-
function injectYouTubeIframeScript() {
|
|
261
|
+
export function injectYouTubeIframeScript() {
|
|
261
262
|
const prom = new Promise( ( resolve ) => {
|
|
262
263
|
if ( globalThis.YT ) {
|
|
263
264
|
return resolve();
|
|
@@ -285,7 +286,8 @@ function injectYouTubeIframeScript() {
|
|
|
285
286
|
|
|
286
287
|
return prom;
|
|
287
288
|
}
|
|
288
|
-
|
|
289
|
+
|
|
290
|
+
export function fallbackCopyToClipboard( text ) {
|
|
289
291
|
const textArea = document.createElement( 'textarea' );
|
|
290
292
|
textArea.value = text;
|
|
291
293
|
|
|
@@ -309,7 +311,7 @@ function fallbackCopyToClipboard( text ) {
|
|
|
309
311
|
document.body.removeChild( textArea );
|
|
310
312
|
}
|
|
311
313
|
|
|
312
|
-
function copyToClipboard() {
|
|
314
|
+
export function copyToClipboard() {
|
|
313
315
|
const copyLinks = document.querySelectorAll( '.copy-to-clipboard' );
|
|
314
316
|
let timeout;
|
|
315
317
|
copyLinks.forEach( ( link ) => {
|
|
@@ -347,16 +349,25 @@ function copyToClipboard() {
|
|
|
347
349
|
} );
|
|
348
350
|
}
|
|
349
351
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
352
|
+
/**
|
|
353
|
+
* Checks whether an element is visible in the viewport.
|
|
354
|
+
* @param {string} element - The dom element to look for.
|
|
355
|
+
* @returns {boolean} True if visible and false if not.
|
|
356
|
+
*/
|
|
357
|
+
export function isInViewport(element) {
|
|
358
|
+
const position = element.getBoundingClientRect();
|
|
353
359
|
return ( position.top >= 0 && position.bottom <= window.innerHeight ) || ( position.top < window.innerHeight && position.bottom >= 0 );
|
|
354
360
|
}
|
|
355
361
|
|
|
356
362
|
/* eslint-disable-next-line */
|
|
357
363
|
const emailRegex = /^[-!#$%&'*+\/0-9=?A-Z^_a-z`{|}~](\.?[-!#$%&'*+\/0-9=?A-Z^_a-z`{|}~])*@[a-zA-Z0-9](-*\.?[a-zA-Z0-9])*\.[a-zA-Z](-?[a-zA-Z0-9])+$/;
|
|
358
364
|
|
|
359
|
-
|
|
365
|
+
/**
|
|
366
|
+
* Checks to make sure a passed string has a valid email address structure and characters.
|
|
367
|
+
* @param {string} email - The email address as a string.
|
|
368
|
+
* @returns {boolean} True if valid and false if not.
|
|
369
|
+
*/
|
|
370
|
+
export function isEmailValid( email ) {
|
|
360
371
|
return emailRegex.test( email );
|
|
361
372
|
};
|
|
362
373
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pernod-ricard-global-cms/jsutils",
|
|
3
|
-
"version": "1.2
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Handy collection of Javascript utility functions",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "jsutils.js",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"test": "
|
|
8
|
+
"test": "jasmine"
|
|
8
9
|
},
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
|
@@ -20,5 +21,8 @@
|
|
|
20
21
|
"gsap": "^3.7.1",
|
|
21
22
|
"jquery": "^3.6.0",
|
|
22
23
|
"swiper": "^6.8.3"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"jasmine": "^3.9.0"
|
|
23
27
|
}
|
|
24
28
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import jsutils from "../jsutils.js";
|
|
2
|
+
|
|
3
|
+
describe("A suite", function() {
|
|
4
|
+
it("fails on a string of letters", function() {
|
|
5
|
+
expect(jsutils.isEmailValid('jkahdb')).toBe(false);
|
|
6
|
+
});
|
|
7
|
+
it("passes with mixed case letters and numbers", function() {
|
|
8
|
+
expect(jsutils.isEmailValid('aS93scFFx@jKoO0908ahdb.com')).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
});
|