How to use the is.date 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 segmentio / analytics.js-integrations / integrations / facebook-pixel / lib / index.js View on Github external
}

    // Standard Events only contains custom properties defined in the configuration
    // If the property is not listed there, we just drop it.
    if (
      isStandardEvent &&
      standardEventsCustomProperties.indexOf(property) < 0
    ) {
      continue;
    }

    var value = properties[property];

    // Dates
    if (dateFields.indexOf(camel(property)) >= 0) {
      if (is.date(value)) {
        payload[property] = value.toISOString().split('T')[0];
        continue;
      }
    }

    // Custom PII properties
    if (customPiiProperties.hasOwnProperty(property)) {
      // hash or drop
      if (customPiiProperties[property] && typeof value === 'string') {
        payload[property] = sha256(value);
      }
      continue;
    }

    // Default PII properties
    var isPropertyPii = defaultPiiProperties.indexOf(property) >= 0;
github segmentio / analytics.js-integrations / integrations / cxense / lib / index.js View on Github external
// send event data
  var properties = track.properties();

  // Cxense requires property values be strings or numbers.
  // Need to sanitize as it will drop events if the payload has other data types.
  var payload = {};
  for (var key in properties) {
    if (properties.hasOwnProperty(key)) {
      var property = properties[key];

      // Numbers and strings are passed as they are.
      // Booleans and dates can be stringified.
      // All other data types are discarded.
      if (is.number(property) || is.string(property)) {
        payload[key] = property;
      } else if (is.bool(property) || is.date(property)) {
        payload[key] = property.toString();
      }
    }
  }
  window.cX.callQueue.push(['sendEvent', track.event(), payload]);
};
github firebase / firebase-tools / src / firestore / encodeFirestoreValue.js View on Github external
return {
        booleanValue: val,
      };
    }
    if (is.integer(val)) {
      return {
        integerValue: val,
      };
    }
    // Integers are handled above, the remaining numbers are treated as doubles
    if (is.number(val)) {
      return {
        doubleValue: val,
      };
    }
    if (is.date(val)) {
      return {
        timestampValue: val.toISOString(),
      };
    }
    if (is.array(val)) {
      var encodedElements = [];
      for (var i = 0; i < val.length; ++i) {
        var enc = encodeHelper(val[i]);
        if (enc) {
          encodedElements.push(enc);
        }
      }
      return {
        arrayValue: {
          values: encodedElements,
        },
github googleapis / nodejs-common / test / grpc-service.js View on Github external
method: function(reqOpts, metadata, grpcOpts) {
              assert(is.date(grpcOpts.deadline));

              assert(grpcOpts.deadline.getTime() > expectedDeadlineRange[0]);
              assert(grpcOpts.deadline.getTime() < expectedDeadlineRange[1]);

              done();
            }
          };
github segmentio / analytics.js-integrations / integrations / wootric / lib / index.js View on Github external
function(results, value, key) {
      var r = results;
      r[convertKey(key, value)] = is.date(value) ? convertDate(value) : value;
      return r;
    },
    {},
github googleapis / nodejs-spanner / src / codec.ts View on Github external
return 'float64';
  }

  if (is.number(field) || field instanceof Int) {
    return 'int64';
  }

  if (is.string(field)) {
    return 'string';
  }

  if (Buffer.isBuffer(field)) {
    return 'bytes';
  }

  if (is.date(field)) {
    return 'timestamp';
  }

  if (field instanceof SpannerDate) {
    return 'date';
  }

  if (Struct.isStruct(field)) {
    const fields = field.map(field => {
      return {
        name: field.name,
        type: getType(field.value),
      };
    });

    return {
github caolan / forms / lib / widgets.js View on Github external
w.formatValue = function (value) {
        if (!value) {
            return null;
        }

        var date = is.date(value) ? value : new Date(value);

        if (isNaN(date.getTime())) {
            return null;
        }

        return date.toISOString().slice(0, 10);
    };
    return w;
github googleapis / nodejs-bigquery / src / table.ts View on Github external
}

    const customTypeConstructorNames = [
      'BigQueryDate',
      'BigQueryDatetime',
      'BigQueryTime',
      'BigQueryTimestamp',
    ];
    const constructorName = value.constructor.name;
    const isCustomType = customTypeConstructorNames.indexOf(constructorName) > -1;

    if (isCustomType) {
      return value.value;
    }

    if (is.date(value)) {
      return value.toJSON();
    }

    if (is.array(value)) {
      return value.map((Table as any).encodeValue_);
    }

    if (is.object(value)) {
      return Object.keys(value).reduce((acc, key) => {
        acc[key] = (Table as any).encodeValue_(value[key]);
        return acc;
      }, {});
    }
    return value;
  }
github googleapis / google-cloud-node / packages / bigtable / src / mutation.js View on Github external
Mutation.createTimeRange = function(start, end) {
  var range = {};

  if (is.date(start)) {
    range.startTimestampMicros = start.getTime();
  }

  if (is.date(end)) {
    range.endTimestampMicros = end.getTime();
  }

  return range;
};

is

the definitive JavaScript type testing library

MIT
Latest version published 5 years ago

Package Health Score

71 / 100
Full package analysis