How to use the tableschema.Schema function in tableschema

To help you get started, we’ve selected a few tableschema 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 frictionlessdata / datapackage-ui / src / reducers / editorPackage.js View on Github external
({descriptor}, {resourceIndex, headers, rows}) => {
      descriptor = cloneDeep(descriptor)
      const schemaDescriptor = descriptor.resources[resourceIndex].schema

      // Get columns
      const columns = []
      for (const [index, header] of headers.entries()) {
        columns[index] = columns[index] || {header, values: []}
        for (const row of rows) {
          columns[index].values.push(row[index])
        }
      }

      // Infer columns
      for (const column of columns) {
        const schema = new Schema()
        schema.infer(column.values, {headers: [column.header]})
        column.descriptor = schema.descriptor.fields[0]
      }

      // Update descriptor
      schemaDescriptor._columns = columns
      for (const [index, column] of columns.entries()) {
        const field = schemaDescriptor.fields[index]
        if (field) schemaDescriptor.fields[index] = {...field, ...column.descriptor}
      }

      return {descriptor}
    },
github frictionlessdata / datapackage-js / src / resource.js View on Github external
const descriptor = this._currentDescriptor
      options.format = descriptor.format || 'csv'
      options.encoding = descriptor.encoding
      const dialect = descriptor.dialect
      if (dialect) {
        if (dialect.header === false || config.DEFAULT_DIALECT.header === false) {
          const fields = (descriptor.schema || {}).fields || []
          options.headers = fields.length ? fields.map(field => field.name) : null
        }
        helpers.validateDialect(dialect)
        for (const key of DIALECT_KEYS) {
          if (dialect[key]) options[key.toLowerCase()] = dialect[key]
        }
      }
      const schemaDescriptor = this._currentDescriptor.schema
      const schema = schemaDescriptor ? new Schema(schemaDescriptor) : null
      this._table = new Table(this.source, {schema, ...options})

    }
    return this._table
  }

tableschema

A library for working with Table Schema in Javascript.

MIT
Latest version published 2 years ago

Package Health Score

48 / 100
Full package analysis