config

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

methods

load

find

* root: string - root directory
* category: string - category name
* ext: string - file extension to convert (yml, json)

findReference

* 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 the 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 the same name with *.vue or *.js in root directory
/*
 * example:
 *   car.entity.yml, bike.entity.json
 *   car.vue, bike.js
 *   {
 *       "car": {...}
 *       "bike": {...}
 *   }
 * */