Skip to content

Commit 1fe2877

Browse files
author
Matt Mayer
authored
docs: add @since tags to all methods (#1337)
1 parent 508082c commit 1fe2877

33 files changed

Lines changed: 599 additions & 0 deletions

File tree

docs/.vitepress/components/api-docs/method.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface Method {
66
readonly returns: string;
77
readonly examples: string; // HTML
88
readonly deprecated: boolean;
9+
readonly since: string;
910
readonly seeAlsos: string[];
1011
}
1112

docs/.vitepress/components/api-docs/method.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ function seeAlsoToUrl(see: string): string {
1919

2020
<div v-html="props.method.description"></div>
2121

22+
<div v-if="props.method.since">
23+
<p>
24+
<em>Available since v<span v-html="props.method.since" /></em>
25+
</p>
26+
</div>
27+
2228
<MethodParameters
2329
v-if="props.method.parameters.length > 0"
2430
:parameters="props.method.parameters"

scripts/apidoc/signature.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { faker } from '../../src';
2121
import {
2222
extractRawExamples,
2323
extractSeeAlsos,
24+
extractSince,
2425
formatTypescript,
2526
isDeprecated,
2627
joinTagParts,
@@ -153,6 +154,7 @@ export function analyzeSignature(
153154
title: prettyMethodName,
154155
description: mdToHtml(toBlock(signature.comment)),
155156
parameters: parameters,
157+
since: extractSince(signature),
156158
returns: typeToText(signature.type),
157159
examples: mdToHtml(`${code}ts\n${examples}${code}`),
158160
deprecated: isDeprecated(signature),

scripts/apidoc/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,14 @@ export function joinTagParts(parts?: CommentDisplayPart[]): string | undefined {
146146
export function isDeprecated(signature: SignatureReflection): boolean {
147147
return extractTagContent('@deprecated', signature).length > 0;
148148
}
149+
150+
/**
151+
* Extracts the "since" tag from the provided signature.
152+
*
153+
* @param signature The signature to check.
154+
*
155+
* @returns the contents of the @since tag
156+
*/
157+
export function extractSince(signature: SignatureReflection): string {
158+
return extractTagContent('@since', signature).join().trim();
159+
}

src/modules/address/index.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class Address {
2828
* faker.address.zipCode() // '17839'
2929
* faker.address.zipCode('####') // '6925'
3030
*
31+
* @since 2.0.1
3132
*/
3233
zipCode(format?: string): string {
3334
// if zip format is not specified, use the zip format defined for the locale
@@ -54,6 +55,8 @@ export class Address {
5455
* @example
5556
* fakerUS.address.zipCodeByState("AK") // '99595'
5657
* fakerUS.address.zipCodeByState("??") // '47683-9880'
58+
*
59+
* @since 5.0.0
5760
*/
5861
zipCodeByState(state: string): string {
5962
const zipRange = this.faker.definitions.address.postcode_by_state?.[state];
@@ -70,6 +73,8 @@ export class Address {
7073
*
7174
* @example
7275
* faker.address.city() // 'East Jarretmouth'
76+
*
77+
* @since 2.0.1
7378
*/
7479
city(format?: string | number): string {
7580
if (format != null) {
@@ -97,6 +102,8 @@ export class Address {
97102
* @example
98103
* faker.address.cityPrefix() // 'East'
99104
*
105+
* @since 2.0.1
106+
*
100107
* @deprecated
101108
* Use `faker.address.city()` instead.
102109
*/
@@ -120,6 +127,8 @@ export class Address {
120127
* @example
121128
* faker.address.citySuffix() // 'mouth'
122129
*
130+
* @since 2.0.1
131+
*
123132
* @deprecated
124133
* Use `faker.address.city()` instead.
125134
*/
@@ -141,6 +150,8 @@ export class Address {
141150
*
142151
* @example
143152
* faker.address.cityName() // 'San Rafael'
153+
*
154+
* @since 5.5.0
144155
*/
145156
cityName(): string {
146157
return this.faker.helpers.arrayElement(
@@ -153,6 +164,8 @@ export class Address {
153164
*
154165
* @example
155166
* faker.address.buildingNumber() // '379'
167+
*
168+
* @since 6.2.0
156169
*/
157170
buildingNumber(): string {
158171
const format = this.faker.helpers.arrayElement(
@@ -167,6 +180,8 @@ export class Address {
167180
*
168181
* @example
169182
* faker.address.street() // 'Schroeder Isle'
183+
*
184+
* @since 7.0.0
170185
*/
171186
street(): string {
172187
const format = this.faker.helpers.arrayElement(
@@ -180,6 +195,8 @@ export class Address {
180195
*
181196
* @example
182197
* fakerDE.address.streetName() // 'Cavill Avenue'
198+
*
199+
* @since 2.0.1
183200
*/
184201
streetName(): string {
185202
if (this.faker.definitions.address.street_name == null) {
@@ -208,6 +225,8 @@ export class Address {
208225
* faker.address.streetAddress() // '0917 O'Conner Estates'
209226
* faker.address.streetAddress(false) // '34830 Erdman Hollow'
210227
* faker.address.streetAddress(true) // '3393 Ronny Way Apt. 742'
228+
*
229+
* @since 2.0.1
211230
*/
212231
streetAddress(useFullAddress: boolean = false): string {
213232
const formats = this.faker.definitions.address.street_address;
@@ -224,6 +243,8 @@ export class Address {
224243
* @example
225244
* faker.address.streetSuffix() // 'Streets'
226245
*
246+
* @since 2.0.1
247+
*
227248
* @deprecated Use faker.address.street() instead.
228249
*/
229250
streetSuffix(): string {
@@ -246,6 +267,8 @@ export class Address {
246267
* @example
247268
* fakerGH.address.streetPrefix() // 'Boame'
248269
*
270+
* @since 3.0.0
271+
*
249272
* @deprecated Use faker.address.street() instead.
250273
*/
251274
streetPrefix(): string {
@@ -266,6 +289,8 @@ export class Address {
266289
*
267290
* @example
268291
* faker.address.secondaryAddress() // 'Apt. 861'
292+
*
293+
* @since 2.0.1
269294
*/
270295
secondaryAddress(): string {
271296
return this.faker.helpers.replaceSymbolWithNumber(
@@ -280,6 +305,8 @@ export class Address {
280305
*
281306
* @example
282307
* faker.address.county() // 'Cambridgeshire'
308+
*
309+
* @since 2.0.1
283310
*/
284311
county(): string {
285312
return this.faker.helpers.arrayElement(
@@ -292,6 +319,8 @@ export class Address {
292319
*
293320
* @example
294321
* faker.address.country() // 'Greece'
322+
*
323+
* @since 2.0.1
295324
*/
296325
country(): string {
297326
return this.faker.helpers.arrayElement(
@@ -309,6 +338,8 @@ export class Address {
309338
* faker.address.countryCode() // 'SJ'
310339
* faker.address.countryCode('alpha-2') // 'GA'
311340
* faker.address.countryCode('alpha-3') // 'TJK'
341+
*
342+
* @since 3.0.0
312343
*/
313344
countryCode(alphaCode: 'alpha-2' | 'alpha-3' = 'alpha-2'): string {
314345
const key =
@@ -322,6 +353,8 @@ export class Address {
322353
*
323354
* @example
324355
* faker.address.state() // 'Georgia'
356+
*
357+
* @since 2.0.1
325358
*/
326359
state(): string {
327360
return this.faker.helpers.arrayElement(
@@ -334,6 +367,8 @@ export class Address {
334367
*
335368
* @example
336369
* faker.address.stateAbbr() // 'ND'
370+
*
371+
* @since 2.0.1
337372
*/
338373
stateAbbr(): string {
339374
return this.faker.helpers.arrayElement(
@@ -351,6 +386,8 @@ export class Address {
351386
* @example
352387
* faker.address.latitude() // '-30.9501'
353388
* faker.address.latitude(10, -10, 5) // '2.68452'
389+
*
390+
* @since 2.0.1
354391
*/
355392
latitude(max: number = 90, min: number = -90, precision: number = 4): string {
356393
return this.faker.datatype
@@ -372,6 +409,8 @@ export class Address {
372409
* @example
373410
* faker.address.longitude() // '-154.0226'
374411
* faker.address.longitude(10, -10, 5) // '-4.03620'
412+
*
413+
* @since 2.0.1
375414
*/
376415
longitude(
377416
max: number = 180,
@@ -397,6 +436,8 @@ export class Address {
397436
* faker.address.direction() // 'Northeast'
398437
* faker.address.direction(false) // 'South'
399438
* faker.address.direction(true) // 'NE'
439+
*
440+
* @since 5.0.0
400441
*/
401442
direction(useAbbr: boolean = false): string {
402443
if (!useAbbr) {
@@ -419,6 +460,8 @@ export class Address {
419460
* faker.address.cardinalDirection() // 'North'
420461
* faker.address.cardinalDirection(false) // 'South'
421462
* faker.address.cardinalDirection(true) // 'N'
463+
*
464+
* @since 5.0.0
422465
*/
423466
cardinalDirection(useAbbr: boolean = false): string {
424467
if (!useAbbr) {
@@ -441,6 +484,8 @@ export class Address {
441484
* faker.address.ordinalDirection() // 'Northeast'
442485
* faker.address.ordinalDirection(false) // 'Northwest'
443486
* faker.address.ordinalDirection(true) // 'NE'
487+
*
488+
* @since 5.0.0
444489
*/
445490
ordinalDirection(useAbbr: boolean = false): string {
446491
if (!useAbbr) {
@@ -465,6 +510,8 @@ export class Address {
465510
* faker.address.nearbyGPSCoordinate() // [ '33.8475', '-170.5953' ]
466511
* faker.address.nearbyGPSCoordinate([33, -170]) // [ '33.0165', '-170.0636' ]
467512
* faker.address.nearbyGPSCoordinate([33, -170], 1000, true) // [ '37.9163', '-179.2408' ]
513+
*
514+
* @since 5.0.0
468515
*/
469516
nearbyGPSCoordinate(
470517
coordinate?: [latitude: number, longitude: number],
@@ -521,6 +568,8 @@ export class Address {
521568
*
522569
* @example
523570
* faker.address.timeZone() // 'Pacific/Guam'
571+
*
572+
* @since 5.1.0
524573
*/
525574
timeZone(): string {
526575
return this.faker.helpers.arrayElement(

0 commit comments

Comments
 (0)