Skip to content

Commit b914a44

Browse files
committed
fix(yaml): auto-convert kebab-case keys to camelCase
1 parent 488bfbf commit b914a44

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/readYAML.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,27 @@ import { resolve } from "node:path";
66
import { parse } from "yaml";
77

88
const CONFIG_VERSION = 1;
9+
const rkebab = /-([a-z])/g;
910

1011
export default async function readYAML( path ) {
1112
if ( !path ) {
1213
return {};
1314
}
1415

1516
const contents = await readFile( resolve( process.cwd(), path ), "utf8" );
16-
const config = await parse( contents );
17+
let config = await parse( contents );
1718

1819
if ( config.version !== CONFIG_VERSION ) {
1920
throw new Error( `Invalid configuration version. Expected ${ CONFIG_VERSION }.` );
2021
}
22+
23+
// Convert kebab-case keys to camelCase
24+
config = Object.fromEntries(
25+
Object.entries( config ).map( ( [ key, value ] ) => [
26+
key.replace( rkebab, ( _, letter ) => letter.toUpperCase() ),
27+
value
28+
] )
29+
);
30+
2131
return config;
2232
}

0 commit comments

Comments
 (0)