@gooddata/js-utils
Advanced tools
Comparing version 1.0.0 to 2.0.0-vojty-ts-2018-05-09T13-16-45-835Z
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.testUtils = exports.postEvents = exports.cookies = exports.env = exports.date = exports.string = undefined; | ||
exports.testUtils = exports.postEvents = exports.cookies = exports.env = exports.string = undefined; | ||
@@ -16,6 +16,2 @@ var _string = require('./utils/string'); | ||
var _date = require('./utils/date'); | ||
var dateUtils = _interopRequireWildcard(_date); | ||
var _cookies = require('./utils/cookies'); | ||
@@ -36,6 +32,6 @@ | ||
exports.string = stringUtils; | ||
exports.date = dateUtils; | ||
exports.env = envUtils; | ||
exports.cookies = cookiesUtils; | ||
exports.postEvents = postEventsUtils; | ||
exports.testUtils = testUtils; | ||
exports.testUtils = testUtils; | ||
//# sourceMappingURL=index.js.map |
@@ -7,6 +7,2 @@ 'use strict'; | ||
var _includes2 = require('lodash/includes'); | ||
var _includes3 = _interopRequireDefault(_includes2); | ||
var _get2 = require('lodash/get'); | ||
@@ -20,8 +16,9 @@ | ||
var _jsCookie2 = _interopRequireDefault(_jsCookie); | ||
var Cookies = _interopRequireWildcard(_jsCookie); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var LOCALE_COOKIE_NAME = 'locale'; | ||
/** | ||
@@ -34,14 +31,10 @@ * Checks if cookies are enabled. | ||
var TEST_COOKIE_VALUE = 'cookievalue'; | ||
if (!navigator.cookieEnabled) { | ||
return false; | ||
} | ||
_jsCookie2.default.set(TEST_COOKIE_NAME, TEST_COOKIE_VALUE); | ||
var cookiesEnabled = _jsCookie2.default.get(TEST_COOKIE_NAME) === TEST_COOKIE_VALUE; | ||
_jsCookie2.default.remove(TEST_COOKIE_NAME); | ||
Cookies.set(TEST_COOKIE_NAME, TEST_COOKIE_VALUE); | ||
var cookiesEnabled = Cookies.get(TEST_COOKIE_NAME) === TEST_COOKIE_VALUE; | ||
Cookies.remove(TEST_COOKIE_NAME); | ||
return cookiesEnabled; | ||
} | ||
/** | ||
@@ -52,5 +45,4 @@ * Gets locale from cookies. | ||
function getLocale() { | ||
return _jsCookie2.default.get(LOCALE_COOKIE_NAME); | ||
return Cookies.get(LOCALE_COOKIE_NAME); | ||
} | ||
/** | ||
@@ -61,8 +53,8 @@ * Sets locale into cookies. | ||
*/ | ||
function setLocale(value) { | ||
var days = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 60; | ||
_jsCookie2.default.set(LOCALE_COOKIE_NAME, value, { expires: days }); | ||
function setLocale(value, days) { | ||
if (days === void 0) { | ||
days = 60; | ||
} | ||
Cookies.set(LOCALE_COOKIE_NAME, value, { expires: days }); | ||
} | ||
/** | ||
@@ -75,21 +67,25 @@ * Set/override locale stored in cookies to whatever locale arrives in bootstrapResource. | ||
*/ | ||
function syncCookieWithBootstrap(data) { | ||
var localeKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
var localeDefault = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'en-US'; | ||
var deps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
var _deps$getLocaleCookie = deps.getLocaleCookie, | ||
getLocaleCookie = _deps$getLocaleCookie === undefined ? getLocale : _deps$getLocaleCookie, | ||
_deps$setLocaleCookie = deps.setLocaleCookie, | ||
setLocaleCookie = _deps$setLocaleCookie === undefined ? setLocale : _deps$setLocaleCookie, | ||
_deps$cookiesEnabled = deps.cookiesEnabled, | ||
cookiesEnabled = _deps$cookiesEnabled === undefined ? areCookiesEnabled : _deps$cookiesEnabled; | ||
function syncCookieWithBootstrap(data, localeKeys, localeDefault, deps) { | ||
if (localeKeys === void 0) { | ||
localeKeys = []; | ||
} | ||
if (localeDefault === void 0) { | ||
localeDefault = 'en-US'; | ||
} | ||
if (deps === void 0) { | ||
deps = {}; | ||
} | ||
var _a = deps.getLocaleCookie, | ||
getLocaleCookie = _a === void 0 ? getLocale : _a, | ||
_b = deps.setLocaleCookie, | ||
setLocaleCookie = _b === void 0 ? setLocale : _b, | ||
_c = deps.cookiesEnabled, | ||
cookiesEnabled = _c === void 0 ? areCookiesEnabled : _c; | ||
var localeBootstrap = (0, _get3.default)(data, ['bootstrapResource', 'accountSetting', 'language']); | ||
var localeCookie = getLocaleCookie(); | ||
var locale = (0, _includes3.default)(localeKeys, localeBootstrap) ? localeBootstrap : localeDefault; | ||
var locale = localeKeys.includes(localeBootstrap) ? localeBootstrap : localeDefault; | ||
if (cookiesEnabled() && localeCookie !== locale) { | ||
setLocaleCookie(locale); | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=cookies.js.map |
@@ -14,2 +14,3 @@ 'use strict'; | ||
return !(hostname === 'localhost' || /getgooddata\.com$/.test(hostname) || /intgdc\.com$/.test(hostname)); | ||
} | ||
} | ||
//# sourceMappingURL=env.js.map |
@@ -8,6 +8,2 @@ 'use strict'; | ||
var _includes2 = require('lodash/includes'); | ||
var _includes3 = _interopRequireDefault(_includes2); | ||
var _get2 = require('lodash/get'); | ||
@@ -23,4 +19,5 @@ | ||
var host = void 0; | ||
var host; | ||
try { | ||
// eslint-disable-next-line no-restricted-globals | ||
host = parent; // do not use check `typeof parent` due to IE11 "Access denied error", instead wrap by try/catch | ||
@@ -30,3 +27,2 @@ } catch (e) { | ||
} | ||
// enable unit testing | ||
@@ -36,3 +32,2 @@ var setHost = exports.setHost = function setHost(h) { | ||
}; | ||
var postEvent = exports.postEvent = function postEvent(product, name, data) { | ||
@@ -46,3 +41,2 @@ host.postMessage({ | ||
}; | ||
var receivers = []; | ||
@@ -53,17 +47,15 @@ var config = { | ||
}; | ||
var receiveListener = function receiveListener(listener) { | ||
return function (event) { | ||
return (0, _get3.default)(event, 'data.gdc.product') === config.product && (0, _includes3.default)(config.validReceivedPostEvents, (0, _get3.default)(event, 'data.gdc.event.name')) ? // check for valid incoming command | ||
return (0, _get3.default)(event, 'data.gdc.product') === config.product && config.validReceivedPostEvents.includes((0, _get3.default)(event, 'data.gdc.event.name')) ? // check for valid incoming command | ||
listener(event) : false; | ||
}; | ||
}; | ||
function setConfig(product, validReceivedPostEvents) { | ||
config = { product: product, validReceivedPostEvents: validReceivedPostEvents }; | ||
} | ||
function addListener(listener) { | ||
var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window; | ||
function addListener(listener, target) { | ||
if (target === void 0) { | ||
target = window; | ||
} | ||
var receiver = receiveListener(listener); | ||
@@ -73,6 +65,6 @@ receivers.push({ listener: listener, receiver: receiver }); | ||
} | ||
function removeListener(listener) { | ||
var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window; | ||
function removeListener(listener, target) { | ||
if (target === void 0) { | ||
target = window; | ||
} | ||
var receiverObj = receivers.find(function (r) { | ||
@@ -85,2 +77,3 @@ return r.listener === listener; | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=post-events.js.map |
@@ -6,11 +6,2 @@ 'use strict'; | ||
}); | ||
var _isNumber2 = require('lodash/isNumber'); | ||
var _isNumber3 = _interopRequireDefault(_isNumber2); | ||
var _isString2 = require('lodash/isString'); | ||
var _isString3 = _interopRequireDefault(_isString2); | ||
exports.shortenText = shortenText; | ||
@@ -21,5 +12,2 @@ exports.escapeRegExp = escapeRegExp; | ||
exports.parseStringToArray = parseStringToArray; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -31,21 +19,17 @@ * @param {String} value string to be shortened | ||
function shortenText(value, options) { | ||
options = options || {}; // eslint-disable-line no-param-reassign | ||
options = options || {}; | ||
var maxLength = options.maxLength; | ||
if (value && maxLength && value.length > maxLength) { | ||
value = value.substr(0, maxLength) + '\u2026'; // eslint-disable-line no-param-reassign | ||
value = value.substr(0, maxLength) + '\u2026'; | ||
} | ||
return value; | ||
} | ||
/** | ||
* Escapes special characters used in regular expressions. | ||
* @param {String} string string to be escaped | ||
* @param {String} s string to be escaped | ||
* @returns {String} | ||
*/ | ||
function escapeRegExp(string) { | ||
return string.replace(/([.*+?^${}()|\[\]\/\\])/g, '\\$1'); // eslint-disable-line | ||
function escapeRegExp(s) { | ||
return s.replace(/([.*+?^${}()|\[\]\/\\])/g, '\\$1'); | ||
} | ||
/** | ||
@@ -64,3 +48,2 @@ * Generates pseudo-random string. | ||
} | ||
/** | ||
@@ -72,7 +55,5 @@ * Replaces non-alphanumerical characters with underscore. | ||
function simplifyText(str) { | ||
var isValid = (0, _isString3.default)(str) || (0, _isNumber3.default)(str); | ||
var s = isValid ? str.toString() : ''; | ||
var s = str && str.toString ? str.toString() : ''; | ||
return s.replace(/[^a-zA-Z0-9]/g, '_').toLowerCase(); | ||
} | ||
/** | ||
@@ -90,3 +71,2 @@ * Parse string in a form of [foo, bar] to an array of objects. | ||
} | ||
if (str.match(/^\[[a-zA-Z0-9]+(,[a-zA-Z0-9]+)*]$/)) { | ||
@@ -97,4 +77,4 @@ // [foo], [foo,bar] | ||
} | ||
return null; | ||
} | ||
} | ||
//# sourceMappingURL=string.js.map |
@@ -8,5 +8,6 @@ "use strict"; | ||
// (C) 2007-2018 GoodData Corporation | ||
function delay() { | ||
var timeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
function delay(timeout) { | ||
if (timeout === void 0) { | ||
timeout = 0; | ||
} | ||
return new Promise(function (resolve) { | ||
@@ -17,2 +18,3 @@ setTimeout(function () { | ||
}); | ||
} | ||
} | ||
//# sourceMappingURL=testUtils.js.map |
{ | ||
"name": "@gooddata/js-utils", | ||
"version": "1.0.0", | ||
"version": "2.0.0-vojty-ts-2018-05-09T13-16-45-835Z", | ||
"description": "Various utils shared on GoodData frontend", | ||
"main": "lib/index.js", | ||
"typings": "index.d.ts", | ||
"files": [ | ||
"README.md", | ||
"LICENSE", | ||
"lib", | ||
"src", | ||
"index.d.ts" | ||
], | ||
"repository": { | ||
@@ -23,23 +14,41 @@ "type": "git", | ||
"homepage": "https://github.com/gooddata/gdc-js-utils", | ||
"main": "./lib/index.js", | ||
"module": "es/index.js", | ||
"typings": "es/index.d.ts", | ||
"files": [ | ||
"README.md", | ||
"LICENSE", | ||
"es", | ||
"lib", | ||
"src" | ||
], | ||
"scripts": { | ||
"build": "rm -rf lib && babel src --out-dir lib --ignore .test.js", | ||
"prepublish": "yarn run build", | ||
"test": "jest --watch" | ||
"build:es": "rm -rf es && tsc -p tsconfig.build.json", | ||
"build:commonjs": "rm -rf lib && BABEL_ENV=commonjs babel es --out-dir lib", | ||
"build": "yarn build:es && yarn build:commonjs", | ||
"prepublish": "yarn build", | ||
"test": "jest --watch", | ||
"tslint": "tslint -t verbose './src/**/*.ts'", | ||
"tslint-ci": "mkdir -p ./ci/results && tslint -t checkstyle -o ./ci/results/tslint-results.xml './src/**/*.ts'", | ||
"validate": "tsc --noEmit && yarn tslint", | ||
"validate-ci": "tsc --noEmit && yarn tslint-ci" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "6.23.0", | ||
"babel-core": "6.23.1", | ||
"babel-jest": "21.0.0", | ||
"babel-plugin-lodash": "3.2.11", | ||
"babel-preset-es2015": "6.22.0", | ||
"babel-preset-stage-2": "6.22.0", | ||
"eslint-config-gooddata": "0.0.13", | ||
"jest": "21.0.0", | ||
"jest-junit": "3.0.0" | ||
"@types/jest": "22.2.3", | ||
"@types/js-cookie": "2.1.0", | ||
"@types/lodash-es": "4.17.0", | ||
"babel-cli": "6.26.0", | ||
"babel-plugin-lodash": "3.3.2", | ||
"babel-preset-es2015": "6.24.1", | ||
"babel-preset-stage-2": "6.24.1", | ||
"jest": "22.4.3", | ||
"jest-junit": "3.0.0", | ||
"ts-jest": "22.4.5", | ||
"tslint-config-gooddata": "0.0.8", | ||
"typescript": "2.8.3" | ||
}, | ||
"dependencies": { | ||
"js-cookie": "2.1.4", | ||
"lodash": "4.17.4", | ||
"moment": "2.17.1", | ||
"moment-timezone": "0.5.11" | ||
"js-cookie": "^2.1.4", | ||
"lodash": "^4.17.4", | ||
"lodash-es": "^4.17.10" | ||
}, | ||
@@ -49,13 +58,23 @@ "license": "BSD-3-Clause", | ||
"transform": { | ||
".js": "babel-jest" | ||
"^.+\\.jsx?$": "<rootDir>/node_modules/babel-jest", | ||
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js" | ||
}, | ||
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.js$", | ||
"transformIgnorePatterns": [ | ||
"<rootDir>/node_modules/(?!lodash-es/.*)" | ||
], | ||
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.ts$", | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"js" | ||
], | ||
"collectCoverageFrom": [ | ||
"src/**/*.js", | ||
"!src/index.js" | ||
] | ||
"src/**/*.ts", | ||
"!src/index.ts" | ||
], | ||
"globals": { | ||
"ts-jest": { | ||
"useBabelrc": true | ||
} | ||
} | ||
} | ||
} |
@@ -25,1 +25,9 @@ GDC JavaScript utilities | ||
Default version increment is patch. | ||
## Build info | ||
This repo has 2 builds: | ||
1. ES modules - primary transpiled TypeScript build which uses `lodash-es` (useful for webpack 2+ and tree-shaking) | ||
2. CommonJS modules - it's transpiled ES build with babel and `lodash-es` is replaced by `lodash` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
55563
3
40
892
33
12
2
1
+ Addedlodash-es@^4.17.10
+ Addedjs-cookie@2.2.1(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlodash-es@4.17.21(transitive)
- Removedmoment@2.17.1
- Removedmoment-timezone@0.5.11
- Removedjs-cookie@2.1.4(transitive)
- Removedlodash@4.17.4(transitive)
- Removedmoment@2.17.1(transitive)
- Removedmoment-timezone@0.5.11(transitive)
Updatedjs-cookie@^2.1.4
Updatedlodash@^4.17.4