How to use the belter/src.isRegex function in belter

To help you get started, we’ve selected a few belter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github krakenjs / zoid / src / component / component / index.js View on Github external
getDomain(props : BuiltInPropsType & P) : string | RegExp {
        if (isRegex(this.domain)) {
            // $FlowFixMe
            return this.domain;
        }

        return this.getInitialDomain(props);
    }
github krakenjs / zoid / src / component / component / index.js View on Github external
getInitialDomain(props : BuiltInPropsType & P) : string {
        if (typeof this.domain === 'string') {
            // $FlowFixMe
            return this.domain;
        }

        let env = props.env || this.defaultEnv;
        // $FlowFixMe
        if (env && typeof this.domain === 'object' && !isRegex(this.domain) && this.domain[env]) {
            return this.domain[env];
        }

        return getDomainFromUrl(this.getUrl(props));
    }
github krakenjs / zoid / dist / module / component / component / index.js View on Github external
Component.prototype.getDomain = function getDomain(props) {
        if (isRegex(this.domain)) {
            // $FlowFixMe
            return this.domain;
        }

        return this.getInitialDomain(props);
    };
github krakenjs / post-robot / src / serialize / function.js View on Github external
return ZalgoPromise.try(() => {
                if (!matchDomain(domain, origin)) {
                    // $FlowFixMe
                    throw new Error(`Method '${ data.name }' domain ${ JSON.stringify(isRegex(meth.domain) ? meth.domain.source : meth.domain) } does not match origin ${ origin } in ${ getDomain(window) }`);
                }
                
                if (ProxyWindow.isProxyWindow(methodSource)) {
                    // $FlowFixMe
                    return methodSource.matchWindow(source, { send }).then(match => {
                        if (!match) {
                            throw new Error(`Method call '${ data.name }' failed - proxy window does not match source in ${ getDomain(window) }`);
                        }
                    });
                }
            }).then(() => {
                return val.apply({ source, origin }, data.args);
github krakenjs / post-robot / src / public / client.js View on Github external
}).then(({ domain: origin } = {}) => {

            if (isRegex(domain)) {
                if (!matchDomain(domain, origin)) {
                    throw new Error(`Remote window domain ${ origin } does not match regex: ${ domain.toString() }`);
                }

                domain = origin;
            }

            if (typeof domain !== 'string' && !Array.isArray(domain)) {
                throw new TypeError(`Expected domain to be a string or array`);
            }

            const actualDomain = domain;
            const logName = (name === MESSAGE_NAME.METHOD && options.data && typeof options.data.name === 'string') ? `${ options.data.name }()` : name;

            return new ZalgoPromise((resolve, reject) => {
github krakenjs / post-robot / src / drivers / listeners.js View on Github external
} else if (domain) {
            throw new Error(`Request listener already exists for ${ name } on domain ${ domain.toString() }`);
        } else {
            throw new Error(`Request listener already exists for ${ name }`);
        }
    }

    const nameListeners = requestListeners.getOrSet(win, () => ({}));
    const domainListeners = getOrSet(nameListeners, name, () => ({}));

    const strDomain = domain.toString();

    let regexListeners;
    let regexListener;

    if (isRegex(domain)) {
        regexListeners = getOrSet(domainListeners, __DOMAIN_REGEX__, () => []);
        regexListener = { regex: domain, listener };
        regexListeners.push(regexListener);
    } else {
        domainListeners[strDomain] = listener;
    }

    return {
        cancel() {
            delete domainListeners[strDomain];

            if (regexListener) {
                regexListeners.splice(regexListeners.indexOf(regexListener, 1));

                if (!regexListeners.length) {
                    delete domainListeners[__DOMAIN_REGEX__];
github krakenjs / post-robot / dist / module / public / client.js View on Github external
}).then(function () {
            var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
                origin = _ref.domain;

            if (isRegex(domain) && !origin) {
                return sayHello(win);
            }
        }).then(function () {
            var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
github krakenjs / post-robot / src / public / client.js View on Github external
}).then(({ domain: origin } = {}) => {

            if (isRegex(domain) && !origin) {
                return sayHello(win);
            }

        }).then(({ domain: origin } = {}) => {
github krakenjs / post-robot / dist / module / public / client.js View on Github external
}).then(function () {
            var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
                origin = _ref2.domain;

            if (isRegex(domain)) {
                if (!matchDomain(domain, origin)) {
                    throw new Error('Remote window domain ' + origin + ' does not match regex: ' + domain.toString());
                }

                domain = origin;
            }

            if (typeof domain !== 'string' && !Array.isArray(domain)) {
                throw new TypeError('Expected domain to be a string or array');
            }

            var actualDomain = domain;
            var logName = name === MESSAGE_NAME.METHOD && options.data && typeof options.data.name === 'string' ? options.data.name + '()' : name;

            return new ZalgoPromise(function (resolve, reject) {