import { IWebDriverCookie } from 'selenium-webdriver' ; import fs from 'fs' ; export class Cookies { private readonly items : IWebDriverCookie [ ] ; constructor ( cookies = [ ] ) { this . items = cookies ; } toString ( ) { return JSON . stringify ( this . items ) ; } saveToFileSync ( path ) { return fs . writeFileSync ( path , JSON . stringify ( this . items ) ) ; } static fromJSONString ( jsonString ) { return new Cookies ( JSON . parse ( jsonString ) ) ; } static fromJSONFileSync ( jsonFilePath ) { const jsonBuf = fs . readFileSync ( jsonFilePath ) ; return Cookies . fromJSONString ( jsonBuf . toString ( 'utf-8' ) ) ; } * [ Symbol . iterator ] ( ) { for ( const item of this . items ) yield item ; } get length ( ) : number { return this . items . length ; } }