All files / src/PerfectWSAdvanced/transform/BaseCustomTransformers GeneratorTransform.ts

100% Statements 12/12
100% Branches 6/6
100% Functions 4/4
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 152x   2x 110x 110x   110x 14499x 14499x   110x 3x 3x 3x 110x
import { PrototypeTransform } from "./PrototypeTransform.js";
 
export class GeneratorTransform extends PrototypeTransform<Iterator<any>> {
    uniqueId = 'Generator'
    serializePrototypes = ['next', 'return', 'throw'];
 
    check(data: any): data is Iterator<any> {
        return (typeof data[Symbol.iterator] === 'function' || typeof data[Symbol.asyncIterator] === 'function') && typeof data.next === 'function';
    }
 
    override deserialize(data: any) {
        data[Symbol.asyncIterator] = () => data
        return data;
    }
}