How to use the is.object function in is

To help you get started, we’ve selected a few is 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 sebelga / gstore-node / src / entity.ts View on Github external
plain(options: PlainOptions | undefined = {}): Partial> & { [key: string]: any } {
    if (!is.object(options)) {
      throw new Error('Options must be an Object');
    }
    const readAll = !!options.readAll || false;
    const virtuals = !!options.virtuals || false;
    const showKey = !!options.showKey || false;

    if (virtuals) {
      // Add any possible virtual properties to the object
      this.entityData = this.__getEntityDataWithVirtuals();
    }

    const data = datastoreSerializer.fromDatastore(this.entityData, this.constructor as Model, {
      readAll,
      showKey,
    });
github googleapis / nodejs-bigtable / src / table.ts View on Github external
ranges.push({
            start: {
              value: lastRowKey,
              inclusive: false,
            },
          });
        } else {
          // Readjust and/or remove ranges based on previous valid row reads.

          // Iterate backward since items may need to be removed.
          for (let index = ranges.length - 1; index >= 0; index--) {
            const range = ranges[index];
            const startValue = is.object(range.start)
              ? range.start.value
              : range.start;
            const endValue = is.object(range.end) ? range.end.value : range.end;
            const isWithinStart =
              !startValue || greaterThanOrEqualTo(startValue, lastRowKey);
            const isWithinEnd = !endValue || lessThan(lastRowKey, endValue);
            if (isWithinStart) {
              if (isWithinEnd) {
                // The lastRowKey is within this range, adjust the start
                // value.
                range.start = {
                  value: lastRowKey,
                  inclusive: false,
                };
              } else {
                // The lastRowKey is past this range, remove this range.
                ranges.splice(index, 1);
              }
            }
github WorkSight / rewire / packages / rewire-graphql / src / ObservableCache.ts View on Github external
write(query: string | undefined, data: ObjectType | any[]): any {
    if (!data) return;
    let cache: any = null;
    if (Array.isArray(data)) {
      cache = this.writeArray(data);
    } else if (is.object(data)) {
      cache = this.writeObject(data);
    }
    if (query) {
      this.store[query] = cache;
    }
    return cache;
  }
github wyntau / koa-validator / lib / validator.js View on Github external
return function(name, fn){
        var objs = {};
        if(is.string(name) && is.function(fn)){
            obj[name] = fn;
        }else if(is.object(name)){
            objs = name;
        }

        Object.keys(objs).forEach(function(name){
            if(validator.hasOwnProperty(name)){
                throw new Error('validator already have method ' + name);
                return;
            }

            if(dicts.indexOf(name) !== -1){
                throw new Error('you have already defined method ' + name);
                return;
            }

            if(!name.match(regex)){
                dicts.push(name);
github googleapis / nodejs-datastore / src / entity.ts View on Github external
const MAX_DATASTORE_VALUE_LENGTH = 1500;
    if (Array.isArray(entities)) {
      for (const entry of entities) {
        if (entry.name && entry.value) {
          if (
            is.string(entry.value) &&
            Buffer.from(entry.value).length > MAX_DATASTORE_VALUE_LENGTH
          ) {
            entry.excludeFromIndexes = true;
          } else {
            continue;
          }
        }
        findLargeProperties_(entry, path.concat('[]'), properties);
      }
    } else if (is.object(entities)) {
      const keys = Object.keys(entities);
      for (const key of keys) {
        findLargeProperties_(
          entities[key],
          path.concat(`${path ? '.' : ''}${key}`),
          properties
        );
      }
    } else if (
      is.string(entities) &&
      Buffer.from(entities).length > MAX_DATASTORE_VALUE_LENGTH
    ) {
      if (properties.indexOf(path) < 0) {
        properties.push(path);
      }
    }
github ianstormtaylor / pg-sql-helpers / src / index.js View on Github external
function COLUMNS(table, value, options = {}) {
  if (table != null && !is.string(table)) {
    value = table
    table = null
  }

  const { delimiter = ', ' } = options
  let keys

  if (is.object(value)) {
    keys = getDefinedKeys(value)
  } else if (is.array(value) && is.object(value[0])) {
    keys = getDefinedKeys(value[0])
  } else if (is.array(value) && is.string(value[0])) {
    keys = value
  } else {
    throw new Error(`The \`COLUMNS\` SQL helper must be passed an object, an array of objects or an array of strings, but you passed: ${value}`)
  }

  const idents = keys.map(k => COLUMN(table, k))
  const query = sql`${sql.join(idents, delimiter)}`
  return query
}
github kaola-fed / console-agent / old / lib / utils / to-json.js View on Github external
const toJSON = (collection) => {
    const json = {};

    for (let [name, value] of Object.entries(collection)) {
        if (is.primitive(value)) {
            json[name] = value;
        } else if (is.object(value)) {
            if (value.toJSON) {
                json[name] = value.toJSON();
            } else {
                json[name] = toJSON(value);
            }
        }
    }

    return json;
}
github ianstormtaylor / pg-sql-helpers / src / index.js View on Github external
function COMPOSITE(object) {
  if (!is.object(object)) {
    throw new Error(`The \`COMPOSITE\` SQL helper must be passed an object, but you passed: ${object}`)
  }

  const keys = getDefinedKeys(object)
  const vals = keys.map(k => sql`${object[k]}`)
  const query = sql`(${sql.join(vals, ', ')})`
  return query
}
github googleapis / nodejs-error-reporting / src / request-extractors / koa.ts View on Github external
export function koaRequestInformationExtractor(
  req: koa.Request,
  res: koa.Response
) {
  const returnObject = new RequestInformationContainer();

  if (
    !is.object(req) ||
    !is.object(res) ||
    is.function(req) ||
    is.function(res) ||
    is.array(req) ||
    is.array(res) ||
    !is.object(req.headers)
  ) {
    return returnObject;
  }

  returnObject
    .setMethod(req.method)
    .setUrl(req.url)
    .setUserAgent(req.headers['user-agent'])
    .setReferrer(req.headers.referrer)
    .setStatusCode(res.status)
    .setRemoteAddress(req.ip);

  return returnObject;
}
github googleapis / nodejs-error-reporting / src / request-extractors / express.ts View on Github external
function extractRemoteAddressFromRequest(req: express.Request) {
  if (typeof req.header('x-forwarded-for') !== 'undefined') {
    return req.header('x-forwarded-for');
  } else if (is.object(req.connection)) {
    return req.connection.remoteAddress;
  }

  return '';
}

is

the definitive JavaScript type testing library

MIT
Latest version published 5 years ago

Package Health Score

71 / 100
Full package analysis