Skip to content

clearlylocal/sheet-to-schema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sheet to Schema

Convert an XLSX spreadsheet into a TypeScript-aware object using a schema:

import { sheetToSchema } from 'sheet-to-schema/mod.ts'
import { xlsxDateTime } from 'sheet-to-schema/dates.ts'

const getData = sheetToSchema({
    sheets: {
        main: {
            match: /sheet.?1/i,
            schema: {
                firstName: {
                    match: /first.?name/i,
                    convert: String,
                },
                lastName: {
                    match: /last.?name/i,
                    convert: String,
                },
                dob: {
                    match: /date.?of.?birth/i,
                    convert: xlsxDateTime,
                    ifError: null,
                },
            },
        },
    },
})

const output = getData(await Deno.readFile('/path/to/file.xlsx'))

// for illustration purposes - types are automatically inferred based on schema
type Data = {
    firstName: string
    lastName: string
    dob: Temporal.PlainDateTime | null
}[]

const data: Data = output.results.main

Uses SheetJS as a dependency. dates.ts additionally uses Temporal polyfill as a dependency.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published