Skip to content

Commit

Permalink
💥 Remove deprecated signatures of fc.lorem
Browse files Browse the repository at this point in the history
Drop any legacy signatures of `fc.lorem` as planned in #992.
Any signature marked as deprecated on `fc.lorem` will be dropped by this PR.

Originally merged as #1504 for alpha versions.
  • Loading branch information
dubzzz committed May 6, 2022
1 parent 14ebd79 commit 8b3fe8f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 49 deletions.
6 changes: 0 additions & 6 deletions documentation/Arbitraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -1106,19 +1106,13 @@ fc.unicodeJson({depthFactor: 'medium'})

- `fc.lorem()`
- `fc.lorem({maxCount?, mode?, size?})`
- _`fc.lorem(maxWordsCount)`_ — _deprecated since v2.6.0 ([#992](https://github.com/dubzzz/fast-check/issues/992))_
- _`fc.lorem(maxCount, sentenceMode)`_ — _deprecated since v2.6.0 ([#992](https://github.com/dubzzz/fast-check/issues/992))_

* with:*

- `maxCount?` — default: `5` — if `sentenceMode` is `true`: lorem ipsum sentence containing at most `maxCount` sentences, otherwise: containing at most `maxCount` words_
- `mode?` — default: `"words"`_enable sentence mode by setting its value to `"sentences"`_
- `maxWordsCount?`_maximal number of words to produce_
- `sentenceMode?` — default: `false`_enable sentence mode_
- `size?` — default: `undefined` [more](#size-explained)_how large should the generated values be?_

_Except if you specified `sentenceMode=true`, `fc.lorem` defaults to words mode_

* Usages*

```js
Expand Down
47 changes: 4 additions & 43 deletions src/arbitrary/lorem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,59 +229,22 @@ function loremWord() {
);
}

/**
* For lorem ipsum strings of words
* @remarks Since 0.0.1
* @public
*/
function lorem(): Arbitrary<string>;
/**
* For lorem ipsum string of words with maximal number of words
*
* @param maxWordsCount - Upper bound of the number of words allowed
*
* @deprecated
* Superceded by `fc.lorem({maxCount})` - see {@link https://github.com/dubzzz/fast-check/issues/992 | #992}.
* Ease the migration with {@link https://github.com/dubzzz/fast-check/tree/main/codemods/unify-signatures | our codemod script}.
*
* @remarks Since 0.0.1
* @public
*/
function lorem(maxWordsCount: number): Arbitrary<string>;
/**
* For lorem ipsum string of words or sentences with maximal number of words or sentences
*
* @param maxWordsCount - Upper bound of the number of words/sentences allowed
* @param sentencesMode - If enabled, multiple sentences might be generated
*
* @deprecated
* Superceded by `fc.lorem({maxCount, mode})` - see {@link https://github.com/dubzzz/fast-check/issues/992 | #992}.
* Ease the migration with {@link https://github.com/dubzzz/fast-check/tree/main/codemods/unify-signatures | our codemod script}.
* @param constraints - Constraints to be applied onto the generated value (since 2.5.0)
*
* @remarks Since 0.0.1
* @public
*/
function lorem(maxWordsCount: number, sentencesMode: boolean): Arbitrary<string>;
/**
* For lorem ipsum string of words or sentences with maximal number of words or sentences
*
* @param constraints - Constraints to be applied onto the generated value
*
* @remarks Since 2.5.0
* @public
*/
function lorem(constraints: LoremConstraints): Arbitrary<string>;
function lorem(...args: [] | [number] | [number, boolean] | [LoremConstraints]): Arbitrary<string> {
const maxWordsCount = typeof args[0] === 'object' ? args[0].maxCount : args[0];
const sentencesMode = typeof args[0] === 'object' ? args[0].mode === 'sentences' : args[1];
const size = typeof args[0] === 'object' ? args[0].size : undefined;
const maxCount = maxWordsCount !== undefined ? maxWordsCount : 5;
export function lorem(constraints: LoremConstraints = {}): Arbitrary<string> {
const { maxCount = 5, mode = 'words', size } = constraints;
if (maxCount < 1) {
throw new Error(`lorem has to produce at least one word/sentence`);
}
const wordArbitrary = loremWord();
const wordArbitraryNext = convertToNext(wordArbitrary);
if (sentencesMode) {
if (mode === 'sentences') {
const sentence = convertToNext(array(wordArbitrary, { minLength: 1, size: 'small' })).map(
wordsToSentenceMapper,
wordsToSentenceUnmapperFor(wordArbitraryNext)
Expand All @@ -301,5 +264,3 @@ function lorem(...args: [] | [number] | [number, boolean] | [LoremConstraints]):
);
}
}

export { lorem };

0 comments on commit 8b3fe8f

Please sign in to comment.