Skip to content

Commit cab0518

Browse files
chore: add fallback option
1 parent 470f1a6 commit cab0518

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

__tests__/utils1.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ describe('normalizeVersion', () => {
214214
expect(normalizeVersion('abc')).toBeUndefined();
215215
expect(normalizeVersion('test/v1.2.3')).toBeUndefined();
216216
});
217+
218+
it('should return fallback', () => {
219+
expect(normalizeVersion('', {fallback: ''})).toBe('');
220+
expect(normalizeVersion('', {fallback: null})).toBe(null);
221+
expect(normalizeVersion('', {fallback: 'abc'})).toBe('abc');
222+
});
217223
});
218224

219225
describe('isValidSemanticVersioning', () => {

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ export const parseVersion = (version: string, options?: { fill?: boolean; cut?:
6363
};
6464
};
6565

66-
export const normalizeVersion = (version: string, options?: { fill?: boolean; cut?: boolean; slice?: number; length?: number; onlyCore?: boolean; }): string | undefined => {
66+
export const normalizeVersion = (version: string, options?: { fill?: boolean; cut?: boolean; slice?: number; length?: number; onlyCore?: boolean; fallback?: string | null }): string | undefined | null => {
6767
const parsed = parseVersion(version, options);
6868
if (!parsed) {
69-
return undefined;
69+
return options?.fallback;
7070
}
7171

7272
if (options?.onlyCore) {

0 commit comments

Comments
 (0)