Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/tests / dist / jest / deps.stringify.js
Size: Mime:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const exotic_1 = require("exotic");
function mapArray(value, coercer) {
    return value.map(coercer);
}
function fromFunctionToStringAndSource(value) {
    try {
        const functionAsString = Function.prototype.call(value);
        return functionAsString
            ? `${value.toString()} { ${functionAsString} }`
            : value.toString();
    }
    catch (toStringException) {
        return value.toString();
    }
}
function fromFunctionToString(value) {
    const functionWithSource = fromFunctionToStringAndSource(value);
    const star = exotic_1.isGenerator(value) ? ' *' : '';
    const asyncd = exotic_1.isAsyncish(value) ? ' async' : '';
    const fnValues = Object.keys(value).length > 0 ? fromObjToString(value) : '';
    return asyncd + star + ' ' + functionWithSource + fnValues;
}
function fromErrorToString(error) {
    //
}
function fromPromiseToString(value) {
    const NOT_RESOLVED = Symbol('@@EMPTY');
    let resolved = NOT_RESOLVED;
    value
        .then(value => {
        resolved = value;
    })
        .catch(error => {
        resolved = `Error!(${error})`;
    });
    function latePromiseToString() {
        return `Promise(${resolved === NOT_RESOLVED ? 'unresolved' : resolved})`;
    }
    return {
        [Symbol.toPrimitive](type) {
            return latePromiseToString();
        },
        toString() {
            return latePromiseToString();
        },
    };
}
function fromObjToString(value) {
    if (exotic_1.isCircular(value)) {
        return '[Circular]';
    }
    const stringified = {};
    Object.keys(value).forEach(key => {
        stringified[key] = castToString(value[key]);
        if (exotic_1.isFrozen(value[key])) {
            stringified[key] = `Frozen(${stringified[key]})`;
        }
        else if (exotic_1.isSealed(value[key])) {
            stringified[key] = `Sealed(${stringified[key]})`;
        }
    });
    const serialized = JSON.stringify(stringified, undefined, 2);
    // Promise()
    if (exotic_1.isPromise(value)) {
        return fromPromiseToString(value);
    }
    // class Eh {}
    if (exotic_1.isClass(value)) {
        return 'Class(' + serialized + ')';
    }
    // function() { arguments }
    else if (exotic_1.isArguments(value)) {
        return 'Arguments(' + serialized + ')';
    }
    // {}, new Object(), Object.create(null)
    else {
        return serialized;
    }
}
function fromArrayToString(value) {
    // EMPTY_ARRAY
    if (value.length === 0 && Object.isExtensible(value) === false) {
        return 'FROZEN_EMPTY_ARRAY';
    }
    // []
    if (value.length === 0) {
        return 'EMPTY_ARRAY';
    }
    // normal
    else {
        return `${mapArray(value, (other) => (exotic_1.isNullOrUndefined(other) ? other : castToString(other)))}`;
    }
}
function castToString(value) {
    // null
    if (exotic_1.isNull(value)) {
        return 'null';
    }
    // undefined
    else if (exotic_1.isUndefined(value)) {
        return 'undefined';
    }
    // new Number
    else if (exotic_1.isBuiltIn(value)) {
        return `BuiltIn(${value})`;
    }
    // Exit early for strings to avoid a performance hit in some environments.
    else if (exotic_1.isString(value)) {
        return value;
    }
    // #
    else if (exotic_1.isNumber(value)) {
        return `#${value}`;
    }
    // Recursively convert values (susceptible to call stack limits).
    else if (exotic_1.isArray(value)) {
        return fromArrayToString(value);
    }
    // proto
    else if (exotic_1.isSymbol(value)) {
        return Symbol.prototype.toString.call(value);
    }
    // function toString :s
    else if (exotic_1.isFunction(value)) {
        return fromFunctionToString(value);
    }
    // {}
    else if (exotic_1.isObj(value)) {
        return fromObjToString(value);
    }
    // -Infinity, -0, 0
    else if (exotic_1.isZeroish(value) && exotic_1.isNegativeInfinity(value)) {
        return '-0';
    }
    // Set(), Map()
    else if (exotic_1.isCollection(value)) {
        throw new TypeError('need to support collections');
    }
    // e.g. ?
    else {
        throw new TypeError('what type? ' + value);
        // throw new TypeError('what type? ' + toTypeTag(value))
        // return String(value)
    }
}
exports.stringify = (x) => castToString(x);
//# sourceMappingURL=deps.stringify.js.map