Skip to content

Commit

Permalink
fix: function renamed importDefault -> jsLoader.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jun 1, 2023
1 parent 743c627 commit e44ccdc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type LoaderFunc<T> = (filepath: string, content: string, jsOption?: LoadC
export type Loader<T> = Record<string, LoaderFunc<T>>;
export interface AutoConfOption<T> {
searchPlaces?: string[];
/** An object that maps extensions to the loader functions responsible for loading and parsing files with those extensions. */
loaders?: Loader<T>;
/** Specify default configuration. It has the lowest priority and is applied after extending config. */
defaluts?: T;
Expand Down
11 changes: 6 additions & 5 deletions core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import path from 'path';
import merge from 'lodash.merge';
import { importDefault, LoadConfOption } from './loader/jsloader';
import { jsLoader, LoadConfOption } from './loader/jsloader';
import { jsonLoader } from './loader/jsonloader';
import { yamlLoader } from './loader/yamlloader';
import { tomlLoader } from './loader/tomlloader';
Expand All @@ -16,6 +16,7 @@ export type LoaderFunc<T> = (filepath: string, content: string, jsOption?: LoadC
export type Loader<T> = Record<string, LoaderFunc<T>>;
export interface AutoConfOption<T> {
searchPlaces?: string[];
/** An object that maps extensions to the loader functions responsible for loading and parsing files with those extensions. */
loaders?: Loader<T>;
/** Specify default configuration. It has the lowest priority and is applied after extending config. */
defaluts?: T;
Expand All @@ -32,10 +33,10 @@ export default function autoConf<T>(namespace: string = 'autoconf', option: Auto
'.yml': yamlLoader,
'.yaml': yamlLoader,
'.toml': tomlLoader,
'.js': importDefault,
'.ts': importDefault,
'.cjs': importDefault,
'.mjs': importDefault,
'.js': jsLoader,
'.ts': jsLoader,
'.cjs': jsLoader,
'.mjs': jsLoader,
...(option.loaders || {}),
};
const pkgPath = path.resolve(cwd, 'package.json');
Expand Down
2 changes: 1 addition & 1 deletion core/src/loader/jsloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ export function loadConf<T>(path: string, option: LoadConfOption = {}): T {
return config.default ?? config;
}

export function importDefault<T>(filepath: string, content: string, option: LoadConfOption = {}): T {
export function jsLoader<T>(filepath: string, content: string, option: LoadConfOption = {}): T {
return loadConf<T>(filepath, option);
}

0 comments on commit e44ccdc

Please sign in to comment.