Skip to content

Commit a6d3c9b

Browse files
authored
msw/utils: Add JSDoc comments for better type support (#12542)
1 parent 50f06b4 commit a6d3c9b

File tree

7 files changed

+31
-0
lines changed

7 files changed

+31
-0
lines changed

packages/crates-io-msw/utils/counters.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const COUNTERS = new Map();
22

3+
/**
4+
* @param {string} counterName
5+
*/
36
export function increment(counterName) {
47
let value = (COUNTERS.get(counterName) || 0) + 1;
58
COUNTERS.set(counterName, value);

packages/crates-io-msw/utils/dates.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* @param {string} a
3+
* @param {string} b
4+
*/
15
export function compareDates(a, b) {
26
let aDate = new Date(a);
37
let bDate = new Date(b);

packages/crates-io-msw/utils/handlers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ export function notFound() {
44
return HttpResponse.json({ errors: [{ detail: 'Not Found' }] }, { status: 404 });
55
}
66

7+
/**
8+
* @param {import("msw").StrictRequest<import("msw").DefaultBodyType>} request
9+
*/
710
export function pageParams(request) {
811
let url = new URL(request.url);
912

packages/crates-io-msw/utils/random.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
/**
2+
* @param {number} seed
3+
*/
14
export function seededRandom(seed) {
25
return mulberry32(seed)();
36
}
47

8+
/**
9+
* @param {number} a
10+
*/
511
function mulberry32(a) {
612
return function () {
713
let t = (a += 0x6d_2b_79_f5);

packages/crates-io-msw/utils/release-tracks.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import semverParse from 'semver/functions/parse.js';
22
import semverSort from 'semver/functions/rsort.js';
33

4+
/**
5+
* @param {{ yanked: boolean, num: string }[]} versions
6+
*/
47
export function calculateReleaseTracks(versions) {
58
let versionNums = versions.filter(it => !it.yanked).map(it => it.num);
69
semverSort(versionNums, { loose: true });
10+
11+
/** @type {Record<string, { highest: string }>} */
712
let tracks = {};
813
for (let num of versionNums) {
914
let semver = semverParse(num, { loose: true });

packages/crates-io-msw/utils/serializers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { underscore } from './strings.js';
22

3+
/**
4+
* @param {{ [s: string]: any; }} model
5+
*/
36
export function serializeModel(model) {
7+
/** @type {{ [s: string]: any; }} */
48
let json = {};
59
for (let [key, value] of Object.entries(model)) {
610
json[underscore(key)] = value;

packages/crates-io-msw/utils/strings.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
/**
2+
* @param {string} str
3+
*/
14
export function dasherize(str) {
25
return str
36
.replace(/([a-z\d])([A-Z])/g, '$1_$2')
47
.toLowerCase()
58
.replace(/[ _]/g, '-');
69
}
710

11+
/**
12+
* @param {string} str
13+
*/
814
export function underscore(str) {
915
return str
1016
.replace(/([a-z\d])([A-Z]+)/g, '$1_$2')

0 commit comments

Comments
 (0)