@@ -188,18 +188,18 @@ function retrieveResolvableSchema(
188
188
// copied and adapted from JsonRefs
189
189
190
190
export const findRefs = ( obj : any ) => {
191
- var refs = { } as any ;
191
+ const refs = { } as any ;
192
192
193
193
// Validate the provided document
194
194
if ( ! isArray ( obj ) && ! isObject ( obj ) ) {
195
195
throw new TypeError ( 'obj must be an Array or an Object' ) ;
196
196
}
197
197
198
198
// Walk the document (or sub document) and find all JSON References
199
- walk ( [ ] , obj , [ ] , function ( { } , node : any , path : any ) {
200
- var processChildren = true ;
201
- var refDetails ;
202
- var refPtr ;
199
+ walk ( [ ] , obj , [ ] , ( { } , node : any , path : any ) => {
200
+ let processChildren = true ;
201
+ let refDetails ;
202
+ let refPtr ;
203
203
204
204
if ( isRefLike ( node , false ) ) {
205
205
refDetails = getRefDetails ( node ) ;
@@ -225,14 +225,14 @@ export const findRefs = (obj: any) => {
225
225
226
226
// pure copy of JsonRefs (added types)
227
227
228
- function walk ( ancestors : any , node : any , path : any , fn : any ) {
229
- var processChildren = true ;
228
+ const walk = ( ancestors : any , node : any , path : any , fn : any ) => {
229
+ let processChildren = true ;
230
230
231
- function walkItem ( item : any , segment : any ) {
231
+ const walkItem = ( item : any , segment : any ) => {
232
232
path . push ( segment ) ;
233
233
walk ( ancestors , item , path , fn ) ;
234
234
path . pop ( ) ;
235
- }
235
+ } ;
236
236
237
237
// Call the iteratee
238
238
if ( isFunction ( fn ) ) {
@@ -245,21 +245,21 @@ function walk(ancestors: any, node: any, path: any, fn: any) {
245
245
246
246
if ( processChildren !== false ) {
247
247
if ( isArray ( node ) ) {
248
- node . forEach ( function ( member , index ) {
248
+ node . forEach ( ( member , index ) => {
249
249
walkItem ( member , index . toString ( ) ) ;
250
250
} ) ;
251
251
} else if ( isObject ( node ) ) {
252
- forOwn ( node , function ( cNode , key ) {
252
+ forOwn ( node , ( cNode , key ) => {
253
253
walkItem ( cNode , key ) ;
254
254
} ) ;
255
255
}
256
256
}
257
257
258
258
ancestors . pop ( ) ;
259
259
}
260
- }
260
+ } ;
261
261
262
- function pathToPtr ( path : any , hashPrefix : any ) {
262
+ const pathToPtr = ( path : any , hashPrefix : any ) => {
263
263
if ( ! isArray ( path ) ) {
264
264
throw new Error ( 'path must be an Array' ) ;
265
265
}
@@ -270,32 +270,32 @@ function pathToPtr(path: any, hashPrefix: any) {
270
270
( path . length > 0 ? '/' : '' ) +
271
271
encodePath ( path ) . join ( '/' )
272
272
) ;
273
- }
273
+ } ;
274
274
275
- function encodePath ( path : any ) {
275
+ const encodePath = ( path : any ) => {
276
276
if ( ! isArray ( path ) ) {
277
277
throw new TypeError ( 'path must be an array' ) ;
278
278
}
279
279
280
- return path . map ( function ( seg ) {
280
+ return path . map ( seg => {
281
281
if ( ! isString ( seg ) ) {
282
282
seg = JSON . stringify ( seg ) ;
283
283
}
284
284
285
285
return seg . replace ( / ~ / g, '~0' ) . replace ( / \/ / g, '~1' ) ;
286
286
} ) ;
287
- }
287
+ } ;
288
288
289
- var uriDetailsCache = { } as any ;
290
- var badPtrTokenRegex = / ~ (?: [ ^ 0 1 ] | $ ) / g;
289
+ const uriDetailsCache = { } as any ;
290
+ const badPtrTokenRegex = / ~ (?: [ ^ 0 1 ] | $ ) / g;
291
291
292
- function getRefDetails ( obj : any ) {
293
- var details = {
292
+ const getRefDetails = ( obj : any ) => {
293
+ const details = {
294
294
def : obj
295
295
} as any ;
296
- var cacheKey ;
297
- var extraKeys ;
298
- var uriDetails ;
296
+ let cacheKey ;
297
+ let extraKeys ;
298
+ let uriDetails ;
299
299
300
300
try {
301
301
if ( isRefLike ( obj , true ) ) {
@@ -345,10 +345,10 @@ function getRefDetails(obj: any) {
345
345
}
346
346
347
347
return details ;
348
- }
348
+ } ;
349
349
350
- function getRefType ( refDetails : any ) {
351
- var type ;
350
+ const getRefType = ( refDetails : any ) => {
351
+ let type ;
352
352
353
353
// Convert the URI reference to one of our types
354
354
switch ( refDetails . uriDetails . reference ) {
@@ -364,22 +364,22 @@ function getRefType(refDetails: any) {
364
364
}
365
365
366
366
return type ;
367
- }
367
+ } ;
368
368
369
- function getExtraRefKeys ( ref : any ) {
370
- return Object . keys ( ref ) . filter ( function ( key ) {
369
+ const getExtraRefKeys = ( ref : any ) => {
370
+ return Object . keys ( ref ) . filter ( key => {
371
371
return key !== '$ref' ;
372
372
} ) ;
373
- }
373
+ } ;
374
374
375
- function parseURI ( uri : string ) {
375
+ const parseURI = ( uri : string ) => {
376
376
// We decode first to avoid doubly encoding
377
377
return parse ( uri ) ;
378
- }
378
+ } ;
379
379
380
- function isPtr ( ptr : any , throwWithDetails : boolean ) {
381
- var valid = true ;
382
- var firstChar ;
380
+ const isPtr = ( ptr : any , throwWithDetails : boolean ) => {
381
+ let valid = true ;
382
+ let firstChar ;
383
383
384
384
try {
385
385
if ( isString ( ptr ) ) {
@@ -406,10 +406,10 @@ function isPtr(ptr: any, throwWithDetails: boolean) {
406
406
}
407
407
408
408
return valid ;
409
- }
409
+ } ;
410
410
411
- function isRefLike ( obj : any , throwWithDetails : boolean ) {
412
- var refLike = true ;
411
+ const isRefLike = ( obj : any , throwWithDetails : boolean ) => {
412
+ let refLike = true ;
413
413
414
414
try {
415
415
if ( ! isPlainObject ( obj ) ) {
@@ -426,4 +426,4 @@ function isRefLike(obj: any, throwWithDetails: boolean) {
426
426
}
427
427
428
428
return refLike ;
429
- }
429
+ } ;
0 commit comments