char/fjson
friendly JSON implementation in TypeScript
git clone https://git.t4t.associates/char/fjson
bb03820
main
1/** options accepted by {@linkcode parse}, {@linkcode parseObject} & co. */ 2export interface Options { 3/** 4* maximum nesting limit (default 128) 5* containers deeper than this fail with a `"nesting"` error 6*/ 7maxDepth ?:number ; 8} 9 10/** default `maxDepth` if not provided */ 11export const DEFAULT_MAX_DEPTH = 128 ; 12 13/** safely retrieve the `maxDepth` value from {@linkcode Options} */ 14export function resolveMaxDepth ( options ?:Options ) :number { 15const maxDepth = options ?. maxDepth ?? DEFAULT_MAX_DEPTH ; 16if ( ! Number . isInteger ( maxDepth ) || ( maxDepth as number ) < 0 ) { 17throw new TypeError ( 18`maxDepth must be a non-negative integer, got ${( maxDepth as number )} ` , 19); 20} 21return maxDepth as number ; 22}