@sumor/config

1.2.6 • Public • Published

config

A Sumor Cloud Tool.
More Documentation Config Loader support yaml and json files. It can load all files in a directory. And automatically convert the file to the specified format.

CI Test Coverage Audit

Installation

npm i @sumor/config --save

Prerequisites

Node.JS version

Require Node.JS version 16.x or above

require Node.JS ES module

As this package is written in ES module, please change the following code in your package.json file:

{
  "type": "module"
}

Usage

entry methods

load

import { load } from '@sumor/config'
  • root: string - root directory
  • name: string - file name
  • ext: string - file extension to convert (yml, json)

meta

load all files in the directory

  • root: string - root directory
  • suffix: string - object suffix which will be load into config (js will only load path)
import { meta } from '@sumor/config'

const config = await meta(process.cwd(), ['js', 'sql'])

/*
Demo directory structure
- root
  - car.json
  - car.sql
  - ship.js
  - plane.yml
*/

// it will load all config files as below
/*
{
  car: {
    name: 'car',
    sql: "..."
  },
  ship: {
    name: 'ship'
    js: '<root>/ship.js'
  },
  plane: {
    name: 'plane'
  }
}
*/

Legacy methods

find

import { find } from '@sumor/config'
  • root: string - root directory
  • category: string - category name
  • ext: string - file extension to convert (yml, json)

findReference

import { findReference } from '@sumor/config'
  • root: string - root directory
  • references: array - reference file extension (vue, js)
  • ext: string - file extension to convert (yml, json)

Load config file

import { load } from '@sumor/config'

const config1 = await load(process.cwd(), 'demo')
// it will load demo.yml or demo.json in root directory

const config2 = await load(process.cwd(), 'demo', 'yaml')
// it will load demo.yml or demo.json in root directory, and convert it to yaml format file

Find config files

import { find } from '@sumor/config'

const config = await find(process.cwd(), 'entity')
// it will load all *.entity.yml or *.entity.json in root directory
/*
 * example:
 *   car.entity.yml, bike.entity.json
 *   {
 *       "car": {...}
 *       "bike": {...}
 *   }
 * */

Find config files from other files

such as .vue, .js files, it has same name config file

import { findReference } from '@sumor/config'

const config = await findReference(process.cwd(), ['vue', 'js'])
// it will load all *.entity.yml or *.entity.json which has same name with *.vue or *.js in root directory
/*
 * example:
 *   car.entity.yml, bike.entity.json
 *   car.vue, bike.js
 *   {
 *       "car": {...}
 *       "bike": {...}
 *   }
 * */

Readme

Keywords

Package Sidebar

Install

npm i @sumor/config

Weekly Downloads

3,664

Version

1.2.6

License

MIT

Unpacked Size

13.6 kB

Total Files

11

Last publish

Collaborators

  • ohnow