@giphy/js-util
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -5,2 +5,12 @@ "use strict"; | ||
var pingbackId = ''; | ||
var idLength = 16; | ||
var noUUIDRandom = function () { | ||
var result = ''; | ||
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
var charactersLength = characters.length; | ||
for (var i = 0; i < idLength; i++) { | ||
result += characters.charAt(Math.floor(Math.random() * charactersLength)); | ||
} | ||
return result; | ||
}; | ||
var getPingbackId = function () { | ||
@@ -17,4 +27,10 @@ // it exists in memory | ||
var hexTime = new Date().getTime().toString(16); // was told to mimic what we had | ||
pingbackId = ("" + hexTime + uuid_1.v4().replace(/-/g, '')).substring(0, 16); // 16 character max | ||
try { | ||
// React Native doesn't support uuid without a polyfill | ||
pingbackId = ("" + hexTime + uuid_1.v4().replace(/-/g, '')).substring(0, idLength); // 16 character max | ||
} | ||
catch (error) { | ||
pingbackId = noUUIDRandom(); | ||
} | ||
try { | ||
// save in storage | ||
@@ -21,0 +37,0 @@ sessionStorage.setItem('giphyPingbackId', pingbackId); |
@@ -21,3 +21,5 @@ "use strict"; | ||
exports.Logger = { | ||
ENABLED: typeof window !== 'undefined' && location && location.search.indexOf('giphy-debug') !== -1, | ||
ENABLED: typeof window !== 'undefined' && | ||
typeof location !== 'undefined' && | ||
location.search.indexOf('giphy-debug') !== -1, | ||
LEVEL: 0, | ||
@@ -24,0 +26,0 @@ PREFIX: 'GiphyJS', |
@@ -11,3 +11,3 @@ { | ||
"name": "@giphy/js-util", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"main": "dist/index.js", | ||
@@ -34,3 +34,3 @@ "description": "Shared giphy js utils", | ||
}, | ||
"gitHead": "e44fe56b1cc4b4f7180a8e6759cb2710bc91f89d" | ||
"gitHead": "89a1f7721ebf52233bd0de4f71b7b8279a79a6df" | ||
} |
import { v4 as uuid } from 'uuid' | ||
let pingbackId = '' | ||
const idLength = 16 | ||
const noUUIDRandom = () => { | ||
let result = '' | ||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' | ||
const charactersLength = characters.length | ||
for (let i = 0; i < idLength; i++) { | ||
result += characters.charAt(Math.floor(Math.random() * charactersLength)) | ||
} | ||
return result | ||
} | ||
const getPingbackId = () => { | ||
@@ -13,4 +24,9 @@ // it exists in memory | ||
const hexTime = new Date().getTime().toString(16) // was told to mimic what we had | ||
pingbackId = `${hexTime}${uuid().replace(/-/g, '')}`.substring(0, 16) // 16 character max | ||
try { | ||
// React Native doesn't support uuid without a polyfill | ||
pingbackId = `${hexTime}${uuid().replace(/-/g, '')}`.substring(0, idLength) // 16 character max | ||
} catch (error) { | ||
pingbackId = noUUIDRandom() | ||
} | ||
try { | ||
// save in storage | ||
@@ -17,0 +33,0 @@ sessionStorage.setItem('giphyPingbackId', pingbackId) |
@@ -10,6 +10,9 @@ /* istanbul ignore next */ | ||
export const Logger = { | ||
ENABLED: typeof window !== 'undefined' && location && location.search.indexOf('giphy-debug') !== -1, | ||
ENABLED: | ||
typeof window !== 'undefined' && | ||
typeof location !== 'undefined' && | ||
location.search.indexOf('giphy-debug') !== -1, | ||
LEVEL: 0, | ||
PREFIX: 'GiphyJS', | ||
debug: function(...msg: any) { | ||
debug: (...msg: any) => { | ||
if (Logger.ENABLED && Logger.LEVEL <= LogLevel.DEBUG) { | ||
@@ -19,3 +22,3 @@ console.debug(Logger.PREFIX, ...msg) // eslint-disable-line no-console | ||
}, | ||
info: function(...msg: any) { | ||
info: (...msg: any) => { | ||
if (Logger.ENABLED && Logger.LEVEL <= LogLevel.INFO) { | ||
@@ -25,3 +28,3 @@ console.info(Logger.PREFIX, ...msg) // eslint-disable-line no-console | ||
}, | ||
warn: function(...msg: any) { | ||
warn: (...msg: any) => { | ||
if (Logger.ENABLED && Logger.LEVEL <= LogLevel.WARN) { | ||
@@ -31,3 +34,3 @@ console.warn(Logger.PREFIX, ...msg) // eslint-disable-line no-console | ||
}, | ||
error: function(...msg: any) { | ||
error: (...msg: any) => { | ||
if (Logger.ENABLED && Logger.LEVEL <= LogLevel.ERROR) { | ||
@@ -34,0 +37,0 @@ console.error(Logger.PREFIX, ...msg) // eslint-disable-line no-console |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72895
1390