Skip to content

Commit

Permalink
Merge branch 'next' into rename-generics
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed May 4, 2023
2 parents cd0084d + 0740aa0 commit a25ba9e
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 37 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/ci.yml
Expand Up @@ -93,8 +93,6 @@ jobs:

- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
with:
version: 7

- name: Set node version to ${{ matrix.node_version }}
uses: actions/setup-node@v3
Expand Down Expand Up @@ -124,8 +122,6 @@ jobs:

- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
with:
version: 7

- name: Install deps
run: pnpm install
Expand All @@ -149,8 +145,6 @@ jobs:

- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
with:
version: 7

- name: Set node version to 18
uses: actions/setup-node@v3
Expand Down Expand Up @@ -181,8 +175,6 @@ jobs:

- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
with:
version: 7

- name: Set node version to 18
uses: actions/setup-node@v3
Expand Down Expand Up @@ -210,8 +202,6 @@ jobs:

- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
with:
version: 7

- name: Set node version to 18
uses: actions/setup-node@v3
Expand Down Expand Up @@ -239,8 +229,6 @@ jobs:

- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
with:
version: 7

- name: Set node version to 18
uses: actions/setup-node@v3
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/pr.yml
Expand Up @@ -21,8 +21,6 @@ jobs:

- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
with:
version: 7

- name: Set node version to 18
uses: actions/setup-node@v3
Expand Down
8 changes: 1 addition & 7 deletions src/locales/ne/location/city_pattern.ts
@@ -1,7 +1 @@
export default [
'{{location.city_prefix}} {{person.firstName}}{{location.city_suffix}}',
'{{location.city_prefix}} {{person.firstName}}',
'{{person.firstName}}{{location.city_suffix}}',
'{{person.lastName}}{{location.city_suffix}}',
'{{location.city_name}}',
];
export default ['{{location.city_name}}'];
8 changes: 1 addition & 7 deletions src/locales/ro/location/city_pattern.ts
@@ -1,7 +1 @@
export default [
'{{location.city_prefix}} {{person.firstName}}{{location.city_suffix}}',
'{{location.city_prefix}} {{person.firstName}}',
'{{person.firstName}}{{location.city_suffix}}',
'{{person.lastName}}{{location.city_suffix}}',
'{{location.city_name}}',
];
export default ['{{location.city_name}}'];
8 changes: 1 addition & 7 deletions src/locales/tr/location/city_pattern.ts
@@ -1,7 +1 @@
export default [
'{{location.city_prefix}} {{person.firstName}}{{location.city_suffix}}',
'{{location.city_prefix}} {{person.firstName}}',
'{{person.firstName}}{{location.city_suffix}}',
'{{person.lastName}}{{location.city_suffix}}',
'{{location.city_name}}',
];
export default ['{{location.city_name}}'];
29 changes: 27 additions & 2 deletions src/modules/helpers/index.ts
Expand Up @@ -764,12 +764,14 @@ export class HelpersModule {
}

/**
* Returns a random key from given object or `undefined` if no key could be found.
* Returns a random key from given object.
*
* @template T The type of the object to select from.
*
* @param object The object to be used.
*
* @throws If the given object is empty.
*
* @example
* faker.helpers.objectKey({ myProperty: 'myValue' }) // 'myProperty'
*
Expand All @@ -781,12 +783,14 @@ export class HelpersModule {
}

/**
* Returns a random value from given object or `undefined` if no key could be found.
* Returns a random value from given object.
*
* @template T The type of object to select from.
*
* @param object The object to be used.
*
* @throws If the given object is empty.
*
* @example
* faker.helpers.objectValue({ myProperty: 'myValue' }) // 'myValue'
*
Expand All @@ -797,6 +801,27 @@ export class HelpersModule {
return object[key];
}

/**
* Returns a random `[key, value]` pair from the given object.
*
* @template T The type of the object to select from.
*
* @param object The object to be used.
*
* @throws If the given object is empty.
*
* @example
* faker.helpers.objectEntry({ prop1: 'value1', prop2: 'value2' }) // ['prop1', 'value1']
*
* @since 8.0.0
*/
objectEntry<T extends Record<string, unknown>>(
object: T
): [keyof T, T[keyof T]] {
const key = this.faker.helpers.objectKey(object);
return [key, object[key]];
}

/**
* Returns random element from the given array.
*
Expand Down
21 changes: 21 additions & 0 deletions test/__snapshots__/helpers.spec.ts.snap
Expand Up @@ -110,6 +110,13 @@ exports[`helpers > 42 > mustache > template with method 1`] = `"Hello John!"`;

exports[`helpers > 42 > mustache > template with string 1`] = `"Hello John!"`;

exports[`helpers > 42 > objectEntry > simple 1`] = `
[
"b",
2,
]
`;

exports[`helpers > 42 > objectKey > simple 1`] = `"b"`;

exports[`helpers > 42 > objectValue > simple 1`] = `2`;
Expand Down Expand Up @@ -343,6 +350,13 @@ exports[`helpers > 1211 > mustache > template with method 1`] = `"Hello John!"`;

exports[`helpers > 1211 > mustache > template with string 1`] = `"Hello John!"`;

exports[`helpers > 1211 > objectEntry > simple 1`] = `
[
"c",
3,
]
`;

exports[`helpers > 1211 > objectKey > simple 1`] = `"c"`;

exports[`helpers > 1211 > objectValue > simple 1`] = `3`;
Expand Down Expand Up @@ -558,6 +572,13 @@ exports[`helpers > 1337 > mustache > template with method 1`] = `"Hello John!"`;

exports[`helpers > 1337 > mustache > template with string 1`] = `"Hello John!"`;

exports[`helpers > 1337 > objectEntry > simple 1`] = `
[
"a",
1,
]
`;

exports[`helpers > 1337 > objectKey > simple 1`] = `"a"`;

exports[`helpers > 1337 > objectValue > simple 1`] = `1`;
Expand Down
25 changes: 25 additions & 0 deletions test/helpers.spec.ts
Expand Up @@ -157,6 +157,10 @@ describe('helpers', () => {
t.it('simple', { a: 1, b: 2, c: 3 });
});

t.describe('objectEntry', (t) => {
t.it('simple', { a: 1, b: 2, c: 3 });
});

t.describe('fake', (t) => {
t.it('with empty string', '')
.it('with a static template', 'my test string')
Expand Down Expand Up @@ -935,6 +939,27 @@ describe('helpers', () => {
});
});

describe('objectEntry', () => {
it('should return a random key, value pair', () => {
const testObject = {
hello: 'to',
you: 'my',
friend: '!',
};
const [key, value] = faker.helpers.objectEntry(testObject);

expect(Object.keys(testObject)).toContain(key);
expect(Object.values(testObject)).toContain(value);
expect(testObject[key]).toEqual(value);
});

it('should throw if given object is empty', () => {
expect(() => faker.helpers.objectEntry({})).toThrowError(
new FakerError('Cannot get value from empty dataset.')
);
});
});

describe('fake()', () => {
it('does allow empty string input', () => {
const actual = faker.helpers.fake('');
Expand Down

0 comments on commit a25ba9e

Please sign in to comment.