Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@guardian/libs

Package Overview
Dependencies
Maintainers
41
Versions
231
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@guardian/libs - npm Package Compare versions

Comparing version 1.3.2 to 1.4.0

dist/cjs/getLocale.d.ts

2

dist/cjs/index.d.ts

@@ -0,2 +1,4 @@

export { getLocale } from './getLocale';
export { isString } from './isString';
export { loadScript } from './loadScript';
export { storage } from './storage';
"use strict";
/* istanbul ignore file */
Object.defineProperty(exports, "__esModule", { value: true });
exports.storage = exports.loadScript = void 0;
exports.storage = exports.loadScript = exports.isString = exports.getLocale = void 0;
var getLocale_1 = require("./getLocale");
Object.defineProperty(exports, "getLocale", { enumerable: true, get: function () { return getLocale_1.getLocale; } });
var isString_1 = require("./isString");
Object.defineProperty(exports, "isString", { enumerable: true, get: function () { return isString_1.isString; } });
var loadScript_1 = require("./loadScript");

@@ -6,0 +10,0 @@ Object.defineProperty(exports, "loadScript", { enumerable: true, get: function () { return loadScript_1.loadScript; } });

@@ -0,2 +1,4 @@

export { getLocale } from './getLocale';
export { isString } from './isString';
export { loadScript } from './loadScript';
export { storage } from './storage';
/* istanbul ignore file */
export { getLocale } from './getLocale';
export { isString } from './isString';
export { loadScript } from './loadScript';
export { storage } from './storage';

@@ -1,1 +0,15 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).gu=e.gu||{},e.gu.libs={}))}(this,(function(e){"use strict";class t{constructor(e){this.__storage=e}isAvailable(){if(void 0!==this.__available)return this.__available;try{const e=(new Date).toString();this.__storage.setItem(e,e);const t=this.__storage.getItem(e)===e;return this.__storage.removeItem(e),this.__available=t}catch(e){return!1}}get(e){var t;if(this.isAvailable())try{const{value:s,expires:r}=JSON.parse(null!==(t=this.__storage.getItem(e))&&void 0!==t?t:"");return r&&new Date>new Date(r)?(this.remove(e),null):s}catch(e){return null}}set(e,t,s){if(this.isAvailable())return this.__storage.setItem(e,JSON.stringify({value:t,expires:s}))}remove(e){if(this.isAvailable())return this.__storage.removeItem(e)}clear(){if(this.isAvailable())return this.__storage.clear()}getRaw(e){return this.isAvailable()?this.__storage.getItem(e):null}setRaw(e,t){if(this.isAvailable())return this.__storage.setItem(e,t)}}const s={local:new t(window.localStorage),session:new t(window.sessionStorage)};e.loadScript=(e,t)=>new Promise(((s,r)=>{var i;const o=document.createElement("script");if(o.src=e,Array.from(document.scripts).some((({src:e})=>o.src===e)))return s();Object.assign(o,t),o.onload=s,o.onerror=()=>{r(new Error("Failed to load script "+e))};const a=document.scripts[0];null===(i=a.parentNode)||void 0===i||i.insertBefore(o,a)})),e.storage=s,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).gu=e.gu||{},e.gu.libs={}))}(this,(function(e){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function t(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{l(n.next(e))}catch(e){o(e)}}function a(e){try{l(n.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}l((n=n.apply(e,t||[])).next())}))}const i=e=>"[object String]"===Object.prototype.toString.call(e);class n{constructor(e){this.__storage=e}isAvailable(){if(void 0!==this.__available)return this.__available;try{const e=(new Date).toString();this.__storage.setItem(e,e);const t=this.__storage.getItem(e)===e;return this.__storage.removeItem(e),this.__available=t}catch(e){return!1}}get(e){var t;if(this.isAvailable())try{const{value:i,expires:n}=JSON.parse(null!==(t=this.__storage.getItem(e))&&void 0!==t?t:"");return n&&new Date>new Date(n)?(this.remove(e),null):i}catch(e){return null}}set(e,t,i){if(this.isAvailable())return this.__storage.setItem(e,JSON.stringify({value:t,expires:i}))}remove(e){if(this.isAvailable())return this.__storage.removeItem(e)}clear(){if(this.isAvailable())return this.__storage.clear()}getRaw(e){return this.isAvailable()?this.__storage.getItem(e):null}setRaw(e,t){if(this.isAvailable())return this.__storage.setItem(e,t)}}const r={local:new n(window.localStorage),session:new n(window.sessionStorage)},o="gu.geolocation",s=e=>i(e)&&/^[A-Z]{2}$/.test(e);e.getLocale=()=>t(void 0,void 0,void 0,(function*(){const e=r.local.get(o);if(s(e))return e;try{const{country:e}=yield fetch("https://api.nextgen.guardianapps.co.uk/geolocation").then((e=>e.json()));if(s(e))return r.local.set(o,e,(t=10,(new Date).getTime()+86400*t)),e}catch(e){}var t;return null})),e.isString=i,e.loadScript=(e,t)=>new Promise(((i,n)=>{var r;const o=document.createElement("script");if(o.src=e,Array.from(document.scripts).some((({src:e})=>o.src===e)))return i();Object.assign(o,t),o.onload=i,o.onerror=()=>{n(new Error("Failed to load script "+e))};const s=document.scripts[0];null===(r=s.parentNode)||void 0===r||r.insertBefore(o,s)})),e.storage=r,Object.defineProperty(e,"__esModule",{value:!0})}));

5

package.json
{
"name": "@guardian/libs",
"version": "1.3.2",
"version": "1.4.0",
"private": false,
"description": "A collection of shared JavaScript libraries for use in Guardian projects",
"description": "A collection of JavaScript libraries for Guardian projects",
"homepage": "https://github.com/guardian/libs#readme",

@@ -57,2 +57,3 @@ "bugs": {

"jest-environment-jsdom-sixteen": "^1.0.3",
"jest-fetch-mock": "^3.0.3",
"npm-run-all": "^4.1.5",

@@ -59,0 +60,0 @@ "prettier": "^2.1.2",

@@ -9,3 +9,3 @@ # Libs

> A collection of shared JavaScript libraries for use in Guardian projects
> A collection of JavaScript libraries for Guardian projects

@@ -38,2 +38,11 @@ <!-- START doctoc generated TOC please keep comment here to allow auto update -->

or
```html
<script src="https://unpkg.com/@guardian/libs"></script>
<script>
// window.gu.libs = { loadScript, storage, etc }
</script>
```
### Bundling

@@ -40,0 +49,0 @@

/* istanbul ignore file */
export { getLocale } from './getLocale';
export { isString } from './isString';
export { loadScript } from './loadScript';
export { storage } from './storage';
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc