Skip to content

Destructuring library methods. It's possible? #743

Closed Locked Answered by ST-DDT
edilsonalves asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, its possible on faker level, but not on module level:

import { faker, UsableLocale } from "@faker-js/faker";

export const customFaker = {
  // Class level functions
  seed: (seed: number | number[]): void => faker.seed(seed),
  setLocale: (locale: UsableLocale): void => faker.setLocale(locale),
  // Original modules
  ...faker,
  // Custom Modules
  custom: {
    object: (): Record<any, any> => JSON.parse(faker.datatype.json()),
  },
};

console.log(customFaker.datatype.number());
console.log(customFaker.custom.object());

See also: #704

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ST-DDT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants