Skip to content

Commit 0b1cee5

Browse files
committed
Merge branch 'main' into christie/analytics
2 parents eeeac61 + 2bfce3b commit 0b1cee5

File tree

5 files changed

+40
-15
lines changed

5 files changed

+40
-15
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"@types/react": "^18.0.3",
4747
"@types/react-dom": "^18.0.0",
4848
"@types/react-test-renderer": "^18.0.0",
49-
"@types/uuid": "^3.4.5",
5049
"jest": "^27.4.4",
5150
"jest-environment-jsdom": "^27.4.4",
5251
"jest-environment-jsdom-global": "^3.0.0",
@@ -66,8 +65,7 @@
6665
"dependencies": {
6766
"hoist-non-react-statics": "^3.3.2",
6867
"launchdarkly-js-client-sdk": "2.22.1",
69-
"lodash.camelcase": "^4.3.0",
70-
"uuid": "^3.3.2"
68+
"lodash.camelcase": "^4.3.0"
7169
},
7270
"peerDependencies": {
7371
"react": "^16.6.3 || ^17.0.0 || ^18.0.0",

src/initLDClient.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const wrapperOptions: LDOptions = {
1717
* @param reactOptions Initialization options for the LaunchDarkly React SDK
1818
* @param options LaunchDarkly initialization options
1919
* @param targetFlags If specified, `launchdarkly-react-client-sdk` will only request and listen to these flags.
20+
* Flag keys must be in their original form as known to LaunchDarkly rather than in their camel-cased form.
2021
*
2122
* @see `ProviderConfig` for more details about the parameters
2223
* @return An initialized client and flags

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export interface ProviderConfig {
6969
/**
7070
* If specified, `launchdarkly-react-client-sdk` will only request and listen to these flags.
7171
* Otherwise, all flags will be requested and listened to.
72+
* Flag keys must be in their original form as known to LaunchDarkly rather than in their camel-cased form.
7273
*/
7374
flags?: LDFlagSet;
7475

src/utils.test.ts

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,44 @@ import { camelCaseKeys, fetchFlags, getFlattenedFlagsFromChangeset } from './uti
22
import { LDClient, LDFlagChangeset, LDFlagSet } from 'launchdarkly-js-client-sdk';
33
import { defaultReactOptions, LDReactOptions } from './types';
44

5+
const caseTestCases = [
6+
['camelCase', 'camelCase'],
7+
['PascalCase', 'pascalCase'],
8+
['kebab-case', 'kebabCase'],
9+
['SCREAMING-KEBAB-CASE', 'screamingKebabCase'],
10+
['snake_case', 'snakeCase'],
11+
['SCREAMING_SNAKE_CASE', 'screamingSnakeCase'],
12+
['camel_Snake_Case', 'camelSnakeCase'],
13+
['Pascal_Snake_Case', 'pascalSnakeCase'],
14+
['Train-Case', 'trainCase'],
15+
// we can possibly drop support for these as they are unlikely used in practice
16+
['snake_kebab-case', 'snakeKebabCase'],
17+
['dragon.case', 'dragonCase'],
18+
['SCREAMING.DRAGON.CASE', 'screamingDragonCase'],
19+
['PascalDragon.Snake_Kebab-Case', 'pascalDragonSnakeKebabCase'],
20+
['SCREAMING.DRAGON_SNAKE_KEBAB-CASE', 'screamingDragonSnakeKebabCase'],
21+
];
22+
523
describe('Utils', () => {
6-
test('camelCaseKeys should ignore system keys', () => {
7-
const bootstrap = {
8-
'test-flag': true,
9-
'another-test-flag': false,
10-
$flagsState: {
11-
'test-flag': { version: 125, variation: 0, trackEvents: true },
12-
'another-test-flag': { version: 18, variation: 1 },
13-
},
14-
$valid: true,
15-
};
24+
describe('camelCaseKeys', () => {
25+
test('should ignore system keys', () => {
26+
const bootstrap = {
27+
'test-flag': true,
28+
'another-test-flag': false,
29+
$flagsState: {
30+
'test-flag': { version: 125, variation: 0, trackEvents: true },
31+
'another-test-flag': { version: 18, variation: 1 },
32+
},
33+
$valid: true,
34+
};
1635

17-
const result = camelCaseKeys(bootstrap);
18-
expect(result).toEqual({ testFlag: true, anotherTestFlag: false });
36+
const result = camelCaseKeys(bootstrap);
37+
expect(result).toEqual({ testFlag: true, anotherTestFlag: false });
38+
});
39+
40+
test.each(caseTestCases)('should handle %s', (key, camelKey) => {
41+
expect(camelCaseKeys({ [key]: false })).toEqual({ [camelKey]: false });
42+
});
1943
});
2044

2145
test('getFlattenedFlagsFromChangeset should return current values of all flags when no targetFlags specified', () => {

src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export const getFlattenedFlagsFromChangeset = (
5454
* @param ldClient LaunchDarkly client
5555
* @param reactOptions Initialization options for the LaunchDarkly React SDK
5656
* @param targetFlags If specified, `launchdarkly-react-client-sdk` will only request and listen to these flags.
57+
* Flag keys must be in their original form as known to LaunchDarkly rather than in their camel-cased form.
5758
*
5859
* @returns an `LDFlagSet` with the current flag values from LaunchDarkly filtered by `targetFlags`.
5960
*/

0 commit comments

Comments
 (0)