Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(locale)!: use snake case for all locale data #2910

Merged
merged 5 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,6 @@ module.exports = defineConfig({
'error',
{
case: 'snakeCase',
// TODO @ST-DDT 2023-10-21: rename the definitions in v9
ignore: [
/chemicalElement\.ts$/,
/directoryPaths\.ts$/,
/mimeTypes\.ts$/,
],
},
],
'unicorn/text-encoding-identifier-case': 'off',
Expand Down
22 changes: 22 additions & 0 deletions docs/guide/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,28 @@ Renamed deprecated locale aliases `cz`, `en_IND`, `ge` and removed `global`.
| `import { faker } from '@faker-js/faker/locale/ge'` | `import { faker } from '@faker-js/faker/locale/ka_GE'` |
| `import { faker } from '@faker-js/faker/locale/global'` | `import { faker } from '@faker-js/faker/locale/base'` |

### Renamed Locale Definitions

The following locale definitions have been renamed

| old | replacement |
| ------------------------------------------- | -------------------------------------------- |
| `faker.definitions.science.chemicalElement` | `faker.definitions.science.chemical_element` |
| `faker.definitions.system.directoryPaths` | `faker.definitions.system.directory_paths` |
| `faker.definitions.system.mimeTypes` | `faker.definitions.system.mime_types` |

With that now all our locale data use the following naming scheme:

```txt
faker.definitions.category_name.entry_name
```

Please keep in mind that property keys of complex objects remain in camel-case.

```txt
faker.definitions.science.chemical_element.atomicNumber
```

### Type Aliases

Removed deprecated type aliases
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/science.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export type ScienceDefinition = LocaleEntry<{
/**
* Some periodic table element information.
*/
chemicalElement: ReadonlyArray<ChemicalElement>;
chemical_element: ReadonlyArray<ChemicalElement>;
}>;
4 changes: 2 additions & 2 deletions src/definitions/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ export type SystemDefinition = LocaleEntry<{
/**
* Returns some common file paths.
*/
directoryPaths: string[];
directory_paths: string[];
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved

/**
* The mime type definitions with some additional information.
*/
mimeTypes: { [mimeType: string]: SystemMimeTypeEntryDefinition };
mime_types: { [mimeType: string]: SystemMimeTypeEntryDefinition };
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
}>;

/**
Expand Down
8 changes: 4 additions & 4 deletions src/locales/base/system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { SystemDefinition } from '../../..';
import directoryPaths from './directoryPaths';
import mimeTypes from './mimeTypes';
import directory_paths from './directory_paths';
import mime_types from './mime_types';

const system: SystemDefinition = {
directoryPaths,
mimeTypes,
directory_paths,
mime_types,
};

export default system;
4 changes: 2 additions & 2 deletions src/locales/en/science/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { ScienceDefinition } from '../../..';
import chemicalElement from './chemicalElement';
import chemical_element from './chemical_element';
import unit from './unit';

const science: ScienceDefinition = {
chemicalElement,
chemical_element,
unit,
};

Expand Down
4 changes: 2 additions & 2 deletions src/locales/eo/science/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { ScienceDefinition } from '../../..';
import chemicalElement from './chemicalElement';
import chemical_element from './chemical_element';
import unit from './unit';

const science: ScienceDefinition = {
chemicalElement,
chemical_element,
unit,
};

Expand Down
4 changes: 2 additions & 2 deletions src/locales/nb_NO/science/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { ScienceDefinition } from '../../..';
import chemicalElement from './chemicalElement';
import chemical_element from './chemical_element';
import unit from './unit';

const science: ScienceDefinition = {
chemicalElement,
chemical_element,
unit,
};

Expand Down
4 changes: 2 additions & 2 deletions src/locales/pl/science/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { ScienceDefinition } from '../../..';
import chemicalElement from './chemicalElement';
import chemical_element from './chemical_element';
import unit from './unit';

const science: ScienceDefinition = {
chemicalElement,
chemical_element,
unit,
};

Expand Down
4 changes: 2 additions & 2 deletions src/locales/zh_CN/science/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { ScienceDefinition } from '../../..';
import chemicalElement from './chemicalElement';
import chemical_element from './chemical_element';
import unit from './unit';

const science: ScienceDefinition = {
chemicalElement,
chemical_element,
unit,
};

Expand Down
2 changes: 1 addition & 1 deletion src/modules/science/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class ScienceModule extends ModuleBase {
*/
chemicalElement(): ChemicalElement {
return this.faker.helpers.arrayElement(
this.faker.definitions.science.chemicalElement
this.faker.definitions.science.chemical_element
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/modules/system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class SystemModule extends ModuleBase {
* @since 3.1.0
*/
mimeType(): string {
const mimeTypeKeys = Object.keys(this.faker.definitions.system.mimeTypes);
const mimeTypeKeys = Object.keys(this.faker.definitions.system.mime_types);

return this.faker.helpers.arrayElement(mimeTypeKeys);
}
Expand Down Expand Up @@ -152,7 +152,7 @@ export class SystemModule extends ModuleBase {
* @since 3.1.0
*/
fileType(): string {
const mimeTypes = this.faker.definitions.system.mimeTypes;
const mimeTypes = this.faker.definitions.system.mime_types;

const typeSet = new Set(
Object.keys(mimeTypes).map((key) => key.split('/')[0])
Expand All @@ -172,7 +172,7 @@ export class SystemModule extends ModuleBase {
* @since 3.1.0
*/
fileExt(mimeType?: string): string {
const mimeTypes = this.faker.definitions.system.mimeTypes;
const mimeTypes = this.faker.definitions.system.mime_types;

if (typeof mimeType === 'string') {
return this.faker.helpers.arrayElement(mimeTypes[mimeType].extensions);
Expand All @@ -193,7 +193,7 @@ export class SystemModule extends ModuleBase {
* @since 3.1.0
*/
directoryPath(): string {
const paths = this.faker.definitions.system.directoryPaths;
const paths = this.faker.definitions.system.directory_paths;
return this.faker.helpers.arrayElement(paths);
}

Expand Down
6 changes: 3 additions & 3 deletions test/modules/science.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('science', () => {

expect(name).toBeTypeOf('string');
expect(() => {
faker.definitions.science.chemicalElement.find(
faker.definitions.science.chemical_element.find(
(element) => element.name === name
);
}).toBeTruthy();
Expand All @@ -39,7 +39,7 @@ describe('science', () => {

expect(symbol).toBeTypeOf('string');
expect(() => {
faker.definitions.science.chemicalElement.find(
faker.definitions.science.chemical_element.find(
(element) => element.symbol === symbol
);
}).toBeTruthy();
Expand All @@ -50,7 +50,7 @@ describe('science', () => {

expect(atomicNumber).toBeTypeOf('number');
expect(() => {
faker.definitions.science.chemicalElement.find(
faker.definitions.science.chemical_element.find(
(element) => element.atomicNumber === atomicNumber
);
}).toBeTruthy();
Expand Down