module import { nanoid } from "nanoid/non-secure" ; import path from "path" ; import util from "util" ; import he from "he" ; const MOCHA_ID_PROP_NAME = "__mocha_id__" ; param { function } ctor param { function } superCtor throws export const inherits = util . inherits ; private param { string } html return { string } export const escape = ( html ) => he . encode ( String ( html ) , { useNamedReferences : false } ) ; private param { Object } obj return { boolean } export const isString = ( obj ) => typeof obj === "string" ; private param { string } text return { string } export const slug = ( text ) => text . toLowerCase ( ) . replace ( /\s+/g , "-" ) . replace ( /[^-\w]/g , "" ) . replace ( /-{2,}/g , "-" ) ; param { string } str return { string } export const clean = ( str ) => { str = str . replace ( /\r\n?|[\n\u2028\u2029]/g , "\n" ) . replace ( /^\uFEFF/ , "" ) . replace ( /^function(?:\s*|\s+[^(]*)\([^)]*\)\s*\{((?:.|\n)*?)\s*\}$|^\([^)]*\)\s*=>\s*(?:\{((?:.|\n)*?)\s*\}|((?:.|\n)*))$/ , "$1$2$3" ) ; var spaces = str . match ( /^\n?( *)/ ) [ 1 ] . length ; var tabs = str . match ( /^\n?(\t*)/ ) [ 1 ] . length ; var re = new RegExp ( "^\n?" + ( tabs ? "\t" : " " ) + "{" + ( tabs || spaces ) + "}" , "gm" ) ; str = str . replace ( re , "" ) ; return str . trim ( ) ; } ; private param { * } value param { string } typeHint returns { string } const emptyRepresentation = ( value , typeHint ) => { switch ( typeHint ) { case "function" : return "[Function]" ; case "object" : return "{}" ; case "array" : return "[]" ; default : return value . toString ( ) ; } } ; private see https param { * } value returns { string } example export const canonicalType = ( value ) => { if ( value === undefined ) { return "undefined" ; } else if ( value === null ) { return "null" ; } else if ( Buffer . isBuffer ( value ) ) { return "buffer" ; } return Object . prototype . toString . call ( value ) . replace ( /^\[.+\s(.+?)]$/ , "$1" ) . toLowerCase ( ) ; } ; private see https param { * } value returns { string } example export const type = ( value ) => { if ( value === null ) return "null" ; const primitives = new Set ( [ "undefined" , "boolean" , "number" , "string" , "bigint" , "symbol" , ] ) ; const _type = typeof value ; if ( _type === "function" ) return _type ; if ( primitives . has ( _type ) ) return _type ; if ( value instanceof String ) return "string" ; if ( value instanceof Error ) return "error" ; if ( Array . isArray ( value ) ) return "array" ; return _type ; } ; /**
 * Stringify `value`. Different behavior depending on type of value:
 *
 * - If `value` is undefined or null, return `'[undefined]'` or `'[null]'`, respectively.
 * - If `value` is not an object, function or array, return result of `value.toString()` wrapped in double-quotes.
 * - If `value` is an *empty* object, function, or array, return result of function
 *    emptyRepresentation .
 * - If `value` has properties, call  canonicalize on it, then return result of
 *   JSON.stringify().
 *
 *  private see exports . type param { * } value return { string } export const stringify = ( value ) => { var typeHint = canonicalType ( value ) ; if ( ! ~ [ "object" , "array" , "function" ] . indexOf ( typeHint ) ) { if ( typeHint === "buffer" ) { var json = Buffer . prototype . toJSON . call ( value ) ; return jsonStringify ( json . data && json . type ? json . data : json , 2 ) . replace ( /,(\n|$)/g , "$1" ) ; } if ( typeHint === "string" && typeof value === "object" ) { value = value . split ( "" ) . reduce ( function ( acc , char , idx ) { acc [ idx ] = char ; return acc ; } , { } ) ; typeHint = "object" ; } else { return jsonStringify ( value ) ; } } for ( var prop in value ) { if ( Object . prototype . hasOwnProperty . call ( value , prop ) ) { return jsonStringify ( canonicalize ( value , null , typeHint ) , 2 ) . replace ( /,(\n|$)/g , "$1" ) ; } } return emptyRepresentation ( value , typeHint ) ; } ; private param { Object } object param { number = } spaces param { number = } depth returns { * } export const jsonStringify = ( object , spaces ? , depth = 1 ) => { if ( typeof spaces === "undefined" ) { return _stringify ( object ) ; } var space = spaces * depth ; var str = Array . isArray ( object ) ? "[" : "{" ; var end = Array . isArray ( object ) ? "]" : "}" ; var length = typeof object . length === "number" ? object . length : Object . keys ( object ) . length ; function repeat ( s , n ) { return new Array ( n ) . join ( s ) ; } function _stringify ( val ) { switch ( canonicalType ( val ) ) { case "null" : case "undefined" : val = "[" + val + "]" ; break ; case "array" : case "object" : val = jsonStringify ( val , spaces , depth + 1 ) ; break ; case "boolean" : case "regexp" : case "symbol" : case "number" : val = val === 0 && 1 / val === - Infinity ? "-0" : val . toString ( ) ; break ; case "bigint" : val = val . toString ( ) + "n" ; break ; case "date" : var sDate = isNaN ( val . getTime ( ) ) ? val . toString ( ) : val . toISOString ( ) ; val = "[Date: " + sDate + "]" ; break ; case "buffer" : var json = val . toJSON ( ) ; json = json . data && json . type ? json . data : json ; val = "[Buffer: " + jsonStringify ( json , 2 , depth + 1 ) + "]" ; break ; default : val = val === "[Function]" || val === "[Circular]" ? val : JSON . stringify ( val ) ; } return val ; } for ( var i in object ) { if ( ! Object . prototype . hasOwnProperty . call ( object , i ) ) { continue ; } -- length ; str += "\n " + repeat ( " " , space ) + ( Array . isArray ( object ) ? "" : '"' + i + '": ' ) + _stringify ( object [ i ] ) + ( length ? "," : "" ) ; } return ( str + ( str . length !== 1 ? "\n" + repeat ( " " , -- space ) + end : end ) ) ; } ; private see exports . stringify param { * } value param { Array } stack param { string } typeHint return { ( Object | Array | Function | string | undefined ) } export const canonicalize = ( value , stack , typeHint ? ) => { var canonicalizedObj ; var prop ; typeHint = typeHint || canonicalType ( value ) ; function withStack ( value , fn ) { stack . push ( value ) ; fn ( ) ; stack . pop ( ) ; } stack = stack || [ ] ; if ( stack . indexOf ( value ) !== - 1 ) { return "[Circular]" ; } switch ( typeHint ) { case "undefined" : case "buffer" : case "null" : canonicalizedObj = value ; break ; case "array" : withStack ( value , function ( ) { canonicalizedObj = value . map ( function ( item ) { return canonicalize ( item , stack ) ; } ) ; } ) ; break ; case "function" : for ( prop in value ) { canonicalizedObj = { } ; break ; } if ( ! canonicalizedObj ) { canonicalizedObj = emptyRepresentation ( value , typeHint ) ; break ; } case "object" : canonicalizedObj = canonicalizedObj || { } ; withStack ( value , function ( ) { Object . keys ( value ) . sort ( ) . forEach ( function ( key ) { canonicalizedObj [ key ] = canonicalize ( value [ key ] , stack ) ; } ) ; } ) ; break ; case "date" : case "number" : case "regexp" : case "boolean" : case "symbol" : canonicalizedObj = value ; break ; default : canonicalizedObj = value + "" ; } return canonicalizedObj ; } ; summary description returns { Function } export const stackTraceFilter = ( ) => { var is = typeof document === "undefined" ? { node : true } : { browser : true } ; var slash = path . sep ; var cwd__ ; if ( is . node ) { cwd__ = cwd ( ) + slash ; } else { cwd__ = ( typeof location === "undefined" ? window . location : location ) . href . replace ( /\/[^/]*$/ , "/" ) ; slash = "/" ; } function isMochaInternal ( line ) { return ( ~ line . indexOf ( "node_modules" + slash + "mocha" + slash ) || ~ line . indexOf ( slash + "mocha.js" ) || ~ line . indexOf ( slash + "mocha.min.js" ) ) ; } function isNodeInternal ( line ) { return ( ~ line . indexOf ( "(timers.js:" ) || ~ line . indexOf ( "(events.js:" ) || ~ line . indexOf ( "(node.js:" ) || ~ line . indexOf ( "(module.js:" ) || ~ line . indexOf ( "GeneratorFunctionPrototype.next (native)" ) || false ) ; } return function ( stack ) { stack = stack . split ( "\n" ) ; stack = stack . reduce ( function ( list , line ) { if ( isMochaInternal ( line ) ) { return list ; } if ( is . node && isNodeInternal ( line ) ) { return list ; } if ( /:\d+:\d+\)?$/ . test ( line ) ) { line = line . replace ( "(" + cwd__ , "(" ) ; } list . push ( line ) ; return list ; } , [ ] ) ; return stack . join ( "\n" ) ; } ; } ; public param { * } value returns { boolean } export const isPromise = ( value ) => typeof value === "object" && value !== null && typeof value . then === "function" ; param { number } value param { number [ ] } range returns { number } export const clamp = ( value , range ) => Math . min ( Math . max ( value , range [ 0 ] ) , range [ 1 ] ) ; public export const noop = function ( ) { } ; description public see https see https see https param { ... * } obj returns { Object } export const createMap = function ( obj ) { return Object . assign . apply ( null , [ Object . create ( null ) ] . concat ( Array . prototype . slice . call ( arguments ) ) ) ; } ; description This differs from  module only in that
 * the argument must be non-empty, because the result is frozen.
 *
 *  see module param { ... * } obj returns { Object } throws export const defineConstants = ( obj ) => { if ( canonicalType ( obj ) !== "object" || ! Object . keys ( obj ) . length ) { throw new TypeError ( "Invalid argument; expected a non-empty object" ) ; } return Object . freeze ( createMap ( obj ) ) ; } ; private export const cwd = function cwd ( ) { return process . cwd ( ) ; } ; returns { boolean } private export const isBrowser = ( ) => Boolean ( ( process as any ) . browser ) ; param { * } value returns { Array < * > } export const castArray = ( value ) => { if ( value === undefined ) { return [ ] ; } if ( value === null ) { return [ null ] ; } if ( typeof value === "object" && ( typeof value [ Symbol . iterator ] === "function" || value . length !== undefined ) ) { return Array . from ( value ) ; } return [ value ] ; } ; export const constants = defineConstants ( { MOCHA_ID_PROP_NAME , } ) ; returns { string } export const uniqueID = ( ) => nanoid ( ) ; export const assignNewMochaID = ( obj ) => { const id = uniqueID ( ) ; Object . defineProperty ( obj , MOCHA_ID_PROP_NAME , { get ( ) { return id ; } , } ) ; return obj ; } ; param { * } obj returns { string | void } export const getMochaID = ( obj ) => obj && typeof obj === "object" ? obj [ MOCHA_ID_PROP_NAME ] : undefined ;