File tree Expand file tree Collapse file tree 7 files changed +31
-0
lines changed
packages/crates-io-msw/utils Expand file tree Collapse file tree 7 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 11const COUNTERS = new Map ( ) ;
22
3+ /**
4+ * @param {string } counterName
5+ */
36export function increment ( counterName ) {
47 let value = ( COUNTERS . get ( counterName ) || 0 ) + 1 ;
58 COUNTERS . set ( counterName , value ) ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {string } a
3+ * @param {string } b
4+ */
15export function compareDates ( a , b ) {
26 let aDate = new Date ( a ) ;
37 let bDate = new Date ( b ) ;
Original file line number Diff line number Diff 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+ */
710export function pageParams ( request ) {
811 let url = new URL ( request . url ) ;
912
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number } seed
3+ */
14export function seededRandom ( seed ) {
25 return mulberry32 ( seed ) ( ) ;
36}
47
8+ /**
9+ * @param {number } a
10+ */
511function mulberry32 ( a ) {
612 return function ( ) {
713 let t = ( a += 0x6d_2b_79_f5 ) ;
Original file line number Diff line number Diff line change 11import semverParse from 'semver/functions/parse.js' ;
22import semverSort from 'semver/functions/rsort.js' ;
33
4+ /**
5+ * @param {{ yanked: boolean, num: string }[] } versions
6+ */
47export 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 } ) ;
Original file line number Diff line number Diff line change 11import { underscore } from './strings.js' ;
22
3+ /**
4+ * @param {{ [s: string]: any; } } model
5+ */
36export 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 ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {string } str
3+ */
14export 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+ */
814export function underscore ( str ) {
915 return str
1016 . replace ( / ( [ a - z \d ] ) ( [ A - Z ] + ) / g, '$1_$2' )
You can’t perform that action at this time.
0 commit comments