How to use the @ditojs/utils.isObject function in @ditojs/utils

To help you get started, we’ve selected a few @ditojs/utils 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 ditojs / dito / packages / server / src / app / Validator.js View on Github external
const schema = clone(jsonSchema, value => {
      if (isObject(value)) {
        if (patch) {
          // Remove all required keywords and formats from schema for patch
          // validation.
          delete value.required
          if (value.format === 'required') {
            delete value.format
          }
        }
        // Convert async `validate()` keywords to `validateAsync()`:
        if (isAsync(value.validate)) {
          value.validateAsync = value.validate
          delete value.validate
        }
        if (!async) {
          // Remove all async keywords for synchronous validation.
          for (const key in value) {
github ditojs / dito / packages / server / src / api / RestGenerator.js View on Github external
function getSettings(verb, handlers, settings) {
  // Only use `settings[verb]` as the settings for this handler, if `settings`
  // contains any of the verbs defined in handlers. If not, then `settings`
  // is a shared object to be used for all verbs:
  let obj = isObject(settings) &&
    Object.keys(handlers).find(verb => settings[verb])
    ? settings[verb]
    : settings || false
  if (!isObject(obj) || !('access' in obj)) {
    // TODO: Improve check by looking for any route settings properties in
    // Object.keys(obj), and only wrap with `access: obj` if obj doesn't contain
    // any of these keys.
    obj = { access: obj }
  }
  return obj
}
github ditojs / dito / packages / server / src / schema / properties.js View on Github external
export function expandSchemaShorthand(schema) {
  // TODO: Consider removing all short-hand schema expansion.
  if (isString(schema)) {
    schema = {
      type: schema
    }
  } else if (isArray(schema)) {
    schema = {
      type: 'array',
      items: schema.length > 1 ? schema : schema[0],
      // The array short-forms sets an empty array as the default.
      default: []
    }
  } else if (
    // Expand objects to `type: 'object'`...
    isObject(schema) &&
    !(
      // ...but only if they don't define any of these properties:
      isString(schema.type) ||
      isString(schema.$ref) ||
      isArray(schema.allOf) ||
      isArray(schema.anyOf) ||
      isArray(schema.oneOf) ||
      isObject(schema.not)
    )
  ) {
    schema = {
      type: 'object',
      properties: {
        ...schema
      },
      additionalProperties: false
github ditojs / dito / packages / server / src / app / Application.js View on Github external
file: pinoLogger
    }[log.requests || log.request]
    // TODO: `log.request` is deprecated, remove later.

    this.use(handleError())
    if (app.responseTime !== false) {
      this.use(responseTime())
    }
    if (logger) {
      this.use(logger())
    }
    if (app.helmet !== false) {
      this.use(helmet())
    }
    if (app.cors !== false) {
      this.use(cors(isObject(app.cors) ? app.cors : {}))
    }
    if (app.compress !== false) {
      this.use(compress(app.compress))
    }
    if (app.etag !== false) {
      this.use(conditional())
      this.use(etag())
    }
  }
github ditojs / dito / packages / admin / src / mixins / DitoMixin.js View on Github external
setupComputed() {
      for (const [key, value] of Object.entries(this.schema.computed || {})) {
        const accessor = isFunction(value)
          ? { get: value }
          : isObject(value) && isFunction(value.get)
            ? value
            : null
        if (accessor) {
          Object.defineProperty(this, key, accessor)
        } else {
          console.error(
            `Invalid computed property definition: ${key}: ${value}`
          )
        }
      }
    },
github ditojs / dito / packages / admin / src / components / DitoClipboard.vue View on Github external
clipboardConfig() {
      return isObject(this.clipboard) ? this.clipboard : {}
    },
github ditojs / dito / packages / admin / src / utils / schema.js View on Github external
function getType(schemaOrType) {
  return isObject(schemaOrType) ? schemaOrType.type : schemaOrType
}
github ditojs / dito / packages / admin / src / mixins / OptionsMixin.js View on Github external
getOptionKey(key) {
      const [option] = this.options
      return isObject(option) && key in option ? key : null
    },
github ditojs / dito / packages / admin / src / utils / schema.js View on Github external
? toObject(descriptions, value => (
      isObject(value) ? value : {
        name: camelize(value, false)
      }
    ))
    : isObject(descriptions) && Object.keys(descriptions).length
github ditojs / dito / packages / server / src / app / Validator.js View on Github external
function hasDefaults(obj) {
  if (isArray(obj)) {
    for (const val of obj) {
      if (val && hasDefaults(val)) {
        return true
      }
    }
  } else if (isObject(obj)) {
    for (const [key, val] of Object.entries(obj)) {
      if (key === 'default' || val && hasDefaults(val)) {
        return true
      }
    }
  }
  return false
}