@gooddata/js-utils
Advanced tools
Comparing version 3.10.3 to 3.10.4
@@ -9,2 +9,3 @@ import * as stringUtils from './utils/string'; | ||
import * as featureFlagsUtils from './utils/featureFlags'; | ||
import * as userUtils from './utils/userUtils'; | ||
import { load } from './utils/trialSnippet'; | ||
@@ -14,2 +15,2 @@ declare const trialSnippet: { | ||
}; | ||
export { stringUtils as string, envUtils as env, cookiesUtils as cookies, postEventsUtils as postEvents, testUtils, walkMe, trialSnippet, translations, featureFlagsUtils, }; | ||
export { stringUtils as string, envUtils as env, cookiesUtils as cookies, postEventsUtils as postEvents, testUtils, walkMe, trialSnippet, translations, featureFlagsUtils, userUtils, }; |
@@ -27,2 +27,4 @@ "use strict"; | ||
exports.featureFlagsUtils = featureFlagsUtils; | ||
var userUtils = __importStar(require("./utils/userUtils")); | ||
exports.userUtils = userUtils; | ||
var trialSnippet_1 = require("./utils/trialSnippet"); | ||
@@ -29,0 +31,0 @@ var trialSnippet = { load: trialSnippet_1.load }; |
@@ -1,2 +0,3 @@ | ||
interface IFeatureFlags { | ||
import { IBootstrapData } from './userUtils'; | ||
export interface IFeatureFlags { | ||
[key: string]: number | boolean | string; | ||
@@ -11,10 +12,2 @@ } | ||
} | ||
interface IBootstrapResource { | ||
current: { | ||
featureFlags: IFeatureFlags; | ||
}; | ||
} | ||
interface IBootstrapData { | ||
bootstrapResource: IBootstrapResource; | ||
} | ||
export declare function shouldHidePPExperience(featureFlags: IFeatureFlags): boolean; | ||
@@ -21,0 +14,0 @@ export declare function isFreemiumEdition(platformEdition: string): boolean; |
@@ -35,1 +35,15 @@ export interface IShortenTextOptions { | ||
export declare function parseStringToArray(str: string): string[] | null; | ||
/** | ||
* Returns a hash code for a string. | ||
* | ||
* The hash code for a string object is computed as | ||
* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] | ||
* using number arithmetic, where s[i] is the i th character | ||
* of the given string, n is the length of the string, | ||
* and ^ indicates exponentiation. | ||
* (The hash value of the empty string is zero.) | ||
* | ||
* @param {string} s a string | ||
* @return {number} a hash code value for the given string. | ||
*/ | ||
export declare function hashCodeString(value: string): number; |
@@ -70,2 +70,27 @@ "use strict"; | ||
exports.parseStringToArray = parseStringToArray; | ||
/** | ||
* Returns a hash code for a string. | ||
* | ||
* The hash code for a string object is computed as | ||
* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] | ||
* using number arithmetic, where s[i] is the i th character | ||
* of the given string, n is the length of the string, | ||
* and ^ indicates exponentiation. | ||
* (The hash value of the empty string is zero.) | ||
* | ||
* @param {string} s a string | ||
* @return {number} a hash code value for the given string. | ||
*/ | ||
function hashCodeString(value) { | ||
if (!value || !value.length) { | ||
return 0; | ||
} | ||
var chars = value.split(''); | ||
var hashCode = chars.reduce(function (hashCode, char) { | ||
var charCode = char.charCodeAt(0); | ||
return (((hashCode << 5) - hashCode) + charCode) | 0; // tslint:disable-line:no-bitwise | ||
}, 0); | ||
return Math.abs(hashCode); | ||
} | ||
exports.hashCodeString = hashCodeString; | ||
//# sourceMappingURL=string.js.map |
{ | ||
"name": "@gooddata/js-utils", | ||
"version": "3.10.3", | ||
"version": "3.10.4", | ||
"description": "Various utils shared on GoodData frontend", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -10,2 +10,3 @@ // (C) 2007-2020 GoodData Corporation | ||
import * as featureFlagsUtils from './utils/featureFlags'; | ||
import * as userUtils from './utils/userUtils'; | ||
import { load } from './utils/trialSnippet'; | ||
@@ -25,2 +26,3 @@ | ||
featureFlagsUtils, | ||
userUtils, | ||
}; |
// (C) 2020 GoodData Corporation | ||
import set from 'lodash/set'; | ||
import cloneDeep = require('lodash/cloneDeep'); | ||
import { IBootstrapData } from './userUtils'; | ||
@@ -12,3 +13,3 @@ const FREE = 'free'; | ||
interface IFeatureFlags { | ||
export interface IFeatureFlags { | ||
[key: string]: number | boolean | string; | ||
@@ -26,12 +27,2 @@ } | ||
interface IBootstrapResource { | ||
current: { | ||
featureFlags: IFeatureFlags; | ||
}; | ||
} | ||
interface IBootstrapData { | ||
bootstrapResource: IBootstrapResource; | ||
} | ||
export function shouldHidePPExperience(featureFlags: IFeatureFlags): boolean { | ||
@@ -38,0 +29,0 @@ const hidePPExperience = featureFlags.hidePixelPerfectExperience as boolean; |
@@ -1,2 +0,2 @@ | ||
// (C) 2007-2018 GoodData Corporation | ||
// (C) 2007-2020 GoodData Corporation | ||
export interface IShortenTextOptions { | ||
@@ -75,1 +75,29 @@ maxLength?: number; | ||
} | ||
/** | ||
* Returns a hash code for a string. | ||
* | ||
* The hash code for a string object is computed as | ||
* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] | ||
* using number arithmetic, where s[i] is the i th character | ||
* of the given string, n is the length of the string, | ||
* and ^ indicates exponentiation. | ||
* (The hash value of the empty string is zero.) | ||
* | ||
* @param {string} s a string | ||
* @return {number} a hash code value for the given string. | ||
*/ | ||
export function hashCodeString(value: string): number { | ||
if (!value || !value.length) { | ||
return 0; | ||
} | ||
const chars: string[] = value.split(''); | ||
const hashCode = chars.reduce((hashCode: number, char: string): number => { | ||
const charCode = char.charCodeAt(0); | ||
return (((hashCode << 5) - hashCode) + charCode) | 0; // tslint:disable-line:no-bitwise | ||
}, 0); | ||
return Math.abs(hashCode); | ||
} |
@@ -57,2 +57,7 @@ // (C) 2020 GoodData Corporation | ||
} | ||
}, | ||
accountSetting: { | ||
links: { | ||
self: '/gdc/profile/user123', | ||
} | ||
} | ||
@@ -59,0 +64,0 @@ } |
@@ -1,2 +0,2 @@ | ||
// (C) 2007-2018 GoodData Corporation | ||
// (C) 2007-2020 GoodData Corporation | ||
import { | ||
@@ -6,3 +6,4 @@ randomString, | ||
simplifyText, | ||
parseStringToArray | ||
parseStringToArray, | ||
hashCodeString | ||
} from '../string'; | ||
@@ -68,1 +69,13 @@ | ||
}); | ||
describe('hashCodeString', () => { | ||
it('should return hash code from string', () => { | ||
const hashCode = hashCodeString('userId123'); | ||
expect(hashCode).toBe(318677548); | ||
}); | ||
it('should return 0 when string is empty', () => { | ||
const hashCode = hashCodeString(''); | ||
expect(hashCode).toBe(0); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
73316
61
1498