0.1.0 • Published 1 year ago

@omapi/loader-textfile v0.1.0

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
1 year ago

OpenMergeAPI > Loader > Text File

Load text files in omapi.

Optionally define a text parser, so e.g. load YAML and TOML files.

Install

npm install @omapi/loader-textfile

Use with omapi

import textfile from '@omapi/loader-textfile'
export default {
	input: 'api',
	output: 'build',
	loaders: [
		textfile({
			// ... options ...
		}),
	],
}

You can use the same loader multiple times with different options.

Options

extensions

List of dot-prefixed file extensions to load as text strings.

  • Type: Array<string>
  • Default: [ ".txt" ]

parse

Specify a custom parser for the string.

  • Type: (data: string) => Object || Promise<Object>
  • Default: no-op, e.g. (input) => { return input }

For example, to load TOML you could do:

import textfile from '@omapi/loader-textfile'
import { load } from 'js-toml'
export default {
	input: 'api',
	output: 'build',
	loaders: [
		// load `.txt` files
		textfile(),
		// load TOML files
		textfile({
			extensions: [ '.toml' ],
			parse: string => load(string),
		}),
	],
}

License

This software and all example code are dedicated to the public domain.

0.1.0

1 year ago

0.0.0

1 year ago