How to use the warehouse.SchemaType.prototype function in warehouse

To help you get started, we’ve selected a few warehouse 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 hexojs / hexo / lib / model / types / moment.js View on Github external
var moment = require('moment'),
  _ = require('lodash'),
  SchemaType = require('warehouse').SchemaType;

var SchemaMoment = module.exports = function(options){
  SchemaType.call(this, options);
};

SchemaMoment.__proto__ = SchemaType;
SchemaMoment.prototype.__proto__ = SchemaType.prototype;

SchemaMoment.prototype.checkRequired = function(value){
  return moment.isMoment(value);
};

var cast = SchemaMoment.prototype.cast = function(value){
  if (!value) return null;
  if (moment.isMoment(value)) return value;

  if (hexo.config.language && !_.isArray(hexo.config.language)){
    return moment(value).locale(hexo.config.language.toLowerCase());
  } else {
    return moment(value);
  }
};
github hexojs / hexo / lib / models / types / moment.js View on Github external
SchemaTypeMoment.prototype.cast = function(value, data) {
  value = SchemaType.prototype.cast.call(this, value, data);
  if (value == null) return value;

  const { options } = this;
  value = toMoment(value);

  if (options.language) value = value.locale(toMomentLocale(options.language));
  if (options.timezone) value = value.tz(options.timezone);

  return value;
};
github hexojs / hexo / lib / models / types / moment.js View on Github external
SchemaTypeMoment.prototype.validate = function(value, data) {
  value = SchemaType.prototype.validate.call(this, value, data);
  if (value == null) return value;

  value = toMoment(value);

  if (!value.isValid()) {
    throw new Error('`' + value + '` is not a valid date!');
  }

  return value;
};