import { Task , CancellablePromise } from '@theintern/common' ; param ms export function sleep ( ms ) { let timer ; return new Task < void > ( function ( resolve ) { timer = setTimeout ( ( ) => { resolve ( ) ; } , ms ) ; } , ( ) => clearTimeout ( timer ) ) ; } /**
 * Annotates the method with additional properties that provide guidance to
 * [[Command]] about how the method interacts with stored context elements.
 */ export function forCommand ( fn , properties ) { return Object . assign ( fn , properties ) ; } /**
 * Get method names, including inherited methods, on an object
 */ export function getMethods ( obj ) { return getOwnProperties ( obj ) . filter ( name => typeof ( < any > obj ) [ name ] === 'function' ) ; } /**
 * Get all property names for an object, including non-enumerable properties
 */ export function getOwnProperties ( obj ) { if ( obj === Object . prototype ) { return [ ] ; } return [ ... Object . getOwnPropertyNames ( obj ) . filter ( name => name !== 'constructor' && name . indexOf ( '__' ) !== 0 ) , ... getOwnProperties ( Object . getPrototypeOf ( obj ) ) ] ; } param using param value param multiple param element returns export function manualFindByLinkText ( using , value , multiple , element ? ) { const check = using === 'link text' ? function ( linkText , text ) { return linkText === text ; } : function ( linkText , text ) { return linkText . indexOf ( text ) !== - 1 ; } ; const links = ( element || document ) . getElementsByTagName ( 'a' ) ; let linkText ; const found = [ ] ; for ( let i = 0 ; i < links . length ; i ++ ) { linkText = links [ i ] . innerText . replace ( /^\s+/ , '' ) . replace ( /\s+$/ , '' ) . replace ( /\s*\r\n\s*/g , '\n' ) . replace ( / +/g , ' ' ) ; if ( check ( linkText , value ) ) { if ( ! multiple ) { return links [ i ] ; } found . push ( links [ i ] ) ; } } if ( multiple ) { return found ; } } /**
 * Converts a function to a string representation suitable for use with the
 * `execute` API endpoint.
 */ export function toExecuteString ( fn ) { if ( typeof fn === 'function' ) { fn = fn . toString ( ) . replace ( /\b__cov_[^,;]+[,;]/g , '' ) ; fn = 'return (' + fn + ').apply(this, arguments);' ; } return fn ; } /**
 * Removes the first line of a stack trace, which in V8 is the string
 * representation of the object holding the stack trace (which is garbage for
 * captured stack traces).
 */ export function trimStack ( stack ) { return stack . replace ( /^[^\n]+/ , '' ) ; }