From bbc67aa2cb60b5fe03d9a77a111045822e461f02 Mon Sep 17 00:00:00 2001 From: Caleb Burton Date: Tue, 25 Jan 2022 12:16:45 -0500 Subject: docs: readme cleanup (#251) --- README.md | 22 ++++++++++++++++++---- src/random.ts | 5 +++++ test/random.spec.ts | 14 ++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c9c77706..06dd665b 100644 --- a/README.md +++ b/README.md @@ -83,13 +83,14 @@ An in-depth overview of the API methods is available in the documentation. The A | Finance | `faker.finance.amount()` | ¥23400 (After setting locale) | | Git | `faker.git.commitMessage()` | feat: add products list page | | Hacker | `faker.hacker.phrase()` | Try to reboot the SQL bus, maybe it will bypass the virtual application! | -| Helpers | `faker.helpers.userCard()` | `{ avatar: ‘...’, email: ‘{ first }{ last }{ number }@{domain}’, first: '...' }`

All of the values are self-consistent (e.g. same first + last name in the email, too) | -| Image | `faker.image.avatar()` | `https://s3.amazonaws.com/uifaces/faces/twitter/martip07/128.jpg` | +| Helpers | `faker.helpers.userCard()` | `{ avatar: '...', email: '{ first }{ last }{ number }@{domain}', first: '...' }`

All of the values are self-consistent (e.g. same first + last name in the email, too) | +| Image | `faker.image.avatar()` | `https://s3.amazonaws.com/uifaces/faces/twitter/martip07/128.jpg` | | Internet | `faker.internet.color()` | #630c7b | | Lorem | `faker.lorem.paragraph()` | Word, words, sentences, slug (lorem-ipsum), paragraph(s), text, lines | | Music | `faker.music.genre()` | R&B | | Name | `faker.name.firstName()` | Cameron | | Phone | `faker.phone.phoneNumber()` | +1 291-299-0192 | +| Random | `faker.random.locale()` | fr_CA | | System | `faker.system.directoryPath()` | C:\Documents\Newsletters\ | | Vehicle | `faker.vehicle.vehicle()` | 2011 Dodge Caravan | @@ -260,9 +261,9 @@ Faker provides many useful utility functions. | slugify | Removes unwanted characters from URI string | | replaceSymbolWithNumber | Parses string for a symbol and replace it with a random number from 1-10 | | replaceSymbols | Parses string for symbols (numbers or letters) and replaces them appropriately (# will be replaced with number, ? with letter and \* will be replaced with number or letter) | - | replaceCreditCardSymbols | Replace symbols in a credit card schems including Luhn checksum | + | replaceCreditCardSymbols | Replace symbols in a credit card schema including Luhn checksum | | repeatString | String repeat helper, alternative to String.prototype.repeat | - | shuffle | Takes an array and randomizes it in place then returns it uses the modern version of the Fisher–Yates algorithm | + | shuffle | Takes an array and randomizes it in place then returns it using the modern version of the Fisher-Yates algorithm | | mustache | Generates a string with mustache {{ }} | | createCard | Generates a human card | | contextualCard | Generates a human contextual card | @@ -369,6 +370,19 @@ Faker provides many useful utility functions. | phoneNumberFormat | Generates a random phone number with requested format (Array index) | | phoneFormats | Generates a random phone number format | +- faker.random + + | API | Description | + | ------------- | --------------------------------------------------------------------------------- | + | arrayElement | Takes an array and returns a random element of the array | + | arrayElements | Takes an array and returns a subset with random elements of the array | + | objectElement | Takes an object and returns a random key or value | + | word | Generates a random word | + | words | Generate `N` random words, with `N` defaulting to a random number between 1 and 3 | + | locale | Generates a random locale | + | alpha | Generates lower/upper alphabetic characters | + | alphaNumeric | Generates alphanumeric characters | + - faker.system | API | Description | diff --git a/src/random.ts b/src/random.ts index 46a6fdba..64fd6948 100644 --- a/src/random.ts +++ b/src/random.ts @@ -151,6 +151,7 @@ export class Random { * boolean * * @method faker.random.boolean + * @deprecated */ boolean(): boolean { console.log( @@ -233,8 +234,12 @@ export class Random { * locale * * @method faker.random.image + * @deprecated */ image() { + console.log( + 'Deprecation Warning: faker.random.image is now located in faker.image.image' + ); return this.faker.image.image(); } diff --git a/test/random.spec.ts b/test/random.spec.ts index ad1951be..727dae14 100644 --- a/test/random.spec.ts +++ b/test/random.spec.ts @@ -235,6 +235,20 @@ describe('random.js', () => { }); }); + describe('image', () => { + it('random.image() uses image module and prints deprecation warning', () => { + const spy_console_log = vi.spyOn(console, 'log'); + const spy_image_image = vi.spyOn(faker.image, 'image'); + faker.random.image(); + expect(spy_image_image).toHaveBeenCalled(); + expect(spy_console_log).toHaveBeenCalledWith( + 'Deprecation Warning: faker.random.image is now located in faker.image.image' + ); + spy_image_image.mockRestore(); + spy_console_log.mockRestore(); + }); + }); + describe('mersenne twister', () => { it('returns a random number without given min / max arguments', () => { const randomNumber = mersenne.rand(); -- cgit v1.2.3