Skip to content

Commit ef72948

Browse files
committed
Uniformalize Normaliser
1 parent 128ece4 commit ef72948

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lib/src/normalizer.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface NormalizedRules {
2222
exact: Record<string, StrategyList[]>;
2323
exactFields: Record<string, StrategyList[]>;
2424
patterns: Record<string, StrategyList[]>;
25-
default: string[];
25+
default: StrategyItem[];
2626
}
2727

2828
export interface NormalizedConfig {
@@ -109,10 +109,17 @@ export const normalizeConfig = async <T extends string = BasicMergeStrategies>(
109109

110110
/* ---------------- helpers ---------------- */
111111

112-
const normalizeDefault = <T extends string>(def?: T | T[]): string[] => {
113-
if (!def) return ["merge"];
114-
const arr = Array.isArray(def) ? def : [def];
115-
return arr.slice();
112+
const normalizeDefault = <T extends string>(def?: T | T[]): StrategyItem[] => {
113+
const arr = def ? (Array.isArray(def) ? def : [def]) : ["merge"];
114+
115+
return arr.map(name => {
116+
const important = name.endsWith("!");
117+
ensureStrategyNameValid(name.slice(0, -1));
118+
return {
119+
name: important ? name.slice(0, -1) : name,
120+
important,
121+
};
122+
});
116123
};
117124

118125
const parseStrategyName = (raw: string): StrategyItem => {

lib/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export interface Config<T extends string = BasicMergeStrategies, TContext = unkn
5252
rules?: RuleTree<T>;
5353

5454
/** Strategy → list of fields to apply it to */
55-
byStrategy?: Partial<Record<ForbidBangEnd<T>, string[]>>;
55+
byStrategy?: Partial<Record<T, string[]>>;
5656

5757
/** Custom strategies (excluding built-in names) */
5858
customStrategies?: Record<Exclude<ForbidBangEnd<T>, BasicMergeStrategies>, StrategyFn<TContext>>;

0 commit comments

Comments
 (0)