How to use the is_js.not function in is_js

To help you get started, we’ve selected a few is_js 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 pbojinov / request-ip / src / index.js View on Github external
function getClientIpFromXForwardedFor(value) {
    if (!is.existy(value)) {
        return null;
    }

    if (is.not.string(value)) {
        throw new TypeError(`Expected a string, got "${typeof value}"`);
    }

    // x-forwarded-for may return multiple IP addresses in the format:
    // "client IP, proxy 1 IP, proxy 2 IP"
    // Therefore, the right-most IP address is the IP address of the most recent proxy
    // and the left-most IP address is the IP address of the originating client.
    // source: http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/x-forwarded-headers.html
    // Azure Web App's also adds a port for some reason, so we'll only use the first part (the IP)
    const forwardedIps = value.split(',').map((e) => {
        const ip = e.trim();
        if (ip.includes(':')) {
            const splitted = ip.split(':');
            // make sure we only use this if it's ipv4 (ip:port)
            if (splitted.length === 2) {
                return splitted[0];
github OpenBazaar / openbazaar-desktop / js / models / profile / Contact.js View on Github external
validate(attrs) {
    const errObj = {};
    const addError = (fieldName, error) => {
      errObj[fieldName] = errObj[fieldName] || [];
      errObj[fieldName].push(error);
    };


    if (attrs.email && is.not.email(attrs.email)) {
      addError('email', app.polyglot.t('contactModelErrors.provideValidEmail'));
    }

    if (attrs.website && is.not.url(attrs.website)) {
      addError('website', app.polyglot.t('contactModelErrors.provideValidURL'));
    }

    const socialAccounts = attrs.social;
    // used to give errors on dupes of the same type
    const groupedByType = socialAccounts.groupBy('type');

    socialAccounts.forEach((socialMd) => {
      const socialAttrs = socialMd.attributes;

      // if there are dupes of the same type, give an error to all
      // dupes after the first one
github qiscus / qiscus-sdk-web-core / src / utils / adapters / custom-event.js View on Github external
subscribeEvent (roomId, callback) {
      if (is.undefined(roomId)) throw new Error('`roomId` required')
      if (is.not.string(roomId)) throw new TypeError('`roomId` must have type of string')
      if (is.undefined(callback)) throw new Error('`callback` required')
      if (is.not.function(callback)) throw new TypeError('`callback` must have type of function')

      const topic = getTopic(roomId)
      // Only allow 1 subcription for now
      if (subscribedTopics[topic]) return
      mqttAdapter.mqtt.subscribe(topic)

      const cb = (payload) => {
        const parsedPayload = JSON.parse(payload)
        callback(parsedPayload)
      }
      events.addListener(topic, cb)
      subscribedTopics[topic] = cb
    },
    unsubscribeEvent (roomId) {
github Albert-Gao / veasy / src / helpers / validationUtils.js View on Github external
function extractUserDefinedMsg(
  handlerName: string,
  schema: FieldRules
) {
  const result = { schema, userErrorText: '' };

  // No user message, just return
  if (is.not.array(schema[handlerName])) return result;

  const currentSchema = schema[handlerName];

  // Handle the case where the value of rule is array
  if (RuleWhichNeedsArray.includes(handlerName)) {
    // No user message, just return
    if (is.not.array(currentSchema[0])) return result;
  }

  // The most common case: [0] is rule and [1] is errText
  const [rule, errText] = currentSchema;
  result.schema[handlerName] = rule;
  result.userErrorText = errText;
  return result;
}
github vadimdemedes / mongorito / lib / mongorito.js View on Github external
// if array is given
	// iterate and call .hook()
	// for each item
	if (Array.isArray(method)) {
		let methods = method;

		methods.forEach(function (method) {
			return self.hook(when, action, method);
		});

		return;
	}

	// if method is a string
	// get the function
	if (is.not.function(method)) {
		let name = method;

		method = this[method];

		if (!method.name) {
			method.name = name;
		}
	}

	// if method is a generator function
	// convert it to promise
	if (isGeneratorFn(method)) {
		method = co.wrap(method);
	}

	// around hooks should be
github Albert-Gao / veasy / src / helpers.js View on Github external
function extractUserDefinedMsg(handlerName, schema) {
  const result = { schema, userErrorText: '' };

  // No user message, just return
  if (is.not.array(schema[handlerName])) return result;

  const currentSchema = schema[handlerName];

  // Handle the case where the value of rule is array
  if (RuleWhichNeedsArray.includes(handlerName)) {
    // No user message, just return
    if (is.not.array(currentSchema[0])) return result;
  }

  // The most common case: [0] is rule and [1] is errText
  result.schema = { [handlerName]: currentSchema[0] };
  // eslint-disable-next-line prefer-destructuring
  result.userErrorText = currentSchema[1];
  return result;
}
github nanopoly / nanopoly / lib / base.js View on Github external
constructor(plugin, options) {
        if (is.not.object(plugin) || is.not.function(plugin.Client) || is.not.function(plugin.Server))
            throw new Error('transport must be a nanopoly plugin');

        this._ClientPlugin = plugin.Client;
        this._ServerPlugin = plugin.Server;
        this._cmd = { CLEAN_SHUTDOWN: '¿§?' };
        this._options = Object.assign({ log: 'error', prefix: 'np' }, options || {});
        this._logger = pino({ level: this._options.log || process.env.LOG_LEVEL });
        this._services = {};
    }
github lithiumtech / lithium-sdk / lib / env-util.js View on Github external
module.exports = function () {
    gutil.env.newStructure = sdkConf.newStructure;
    gutil.env.copyFiles = (gutil.env.newStructure ? sdkConf.newStructureCopyFiles : sdkConf.copyFiles) || [];
    if (is.object(sdkConf.ng) && is.not.empty(sdkConf.ng)) {
        var compPath = gutil.env.newStructure ? '../limuirs/src/components' : 'limuirs/src/components';
        gutil.env.ng = {
            module: sdkConf.ng.module || 'li',
            textProperties: getSourcePaths(sdkConf.ng.addTextProperties || [])
                .concat(['src/directives', 'src/services', compPath]),
            moduleDependencyMap: sdkConf.ng.moduleDependencies || {},
            useNewModuleDependenciesFormat: sdkConf.ng.useNewModuleDependenciesFormat,
            moduleDependencies: (function () {
                var deps = [];
                Object.keys(sdkConf.ng.moduleDependencies || {}).forEach(function (key) {
                    var moduleDeps = sdkConf.ng.moduleDependencies[key];
                    if (Array.isArray(moduleDeps)) {
                        deps = deps.concat(moduleDeps);
                    }
                    if ('dev' in moduleDeps && Array.isArray(moduleDeps.dev)) {
                        deps = deps.concat(sdkConf.ng.moduleDependencies[key].dev);
github nanopoly / nanopoly / src / server.js View on Github external
async _onMessage(m) {
        const { s: service, m: method, id } = m;
        if (is.not.string(service) || is.not.string(method) || is.not.string(id)) throw new Error('invalid message');
        else if (!this._services[service]) throw new Error(`unknown service(${ service })`);
        else if (method.startsWith('_') || is.not.function(this._services[service].c[method]))
            throw new Error(`invalid method(${ method })`);
        else if (this._services[service].c[method].constructor.name !== 'AsyncFunction')
            throw new Error(`invalid method(${ method })`);

        return await this._services[service].c[method](m);
    }
github OpenBazaar / openbazaar-desktop / js / models / listing / Listing.js View on Github external
const addError = (fieldName, error) => {
      errObj[fieldName] = errObj[fieldName] || [];
      errObj[fieldName].push(error);
    };
    const metadata = {
      ...this.get('metadata').toJSON(),
      ...attrs.metadata,
    };
    const contractType = metadata.contractType;
    const item = {
      ...this.get('item').toJSON(),
      ...attrs.item,
    };

    if (attrs.refundPolicy) {
      if (is.not.string(attrs.refundPolicy)) {
        addError('refundPolicy', 'The return policy must be of type string.');
      } else if (attrs.refundPolicy.length > this.max.refundPolicyLength) {
        addError('refundPolicy', app.polyglot.t('listingModelErrors.returnPolicyTooLong'));
      }
    }

    if (attrs.termsAndConditions) {
      if (is.not.string(attrs.termsAndConditions)) {
        addError('termsAndConditions', 'The terms and conditions must be of type string.');
      } else if (attrs.termsAndConditions.length > this.max.termsAndConditionsLength) {
        addError('termsAndConditions',
          app.polyglot.t('listingModelErrors.termsAndConditionsTooLong'));
      }
    }

    if (contractType === 'PHYSICAL_GOOD') {