From 0d67b0c3a511f80e12bc632065f02b4521bc01b4 Mon Sep 17 00:00:00 2001 From: j3rem1e Date: Mon, 1 Mar 2021 12:47:55 +0100 Subject: [PATCH] Improve generated stories ID --- src/parser/extract-id.test.js | 2 +- src/parser/extract-id.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parser/extract-id.test.js b/src/parser/extract-id.test.js index c318e25..0bcaf38 100644 --- a/src/parser/extract-id.test.js +++ b/src/parser/extract-id.test.js @@ -2,6 +2,6 @@ import { extractId } from './extract-id'; describe('extract-id', () => { test('name with spaces', () => { - expect(extractId({ name: 'Name with spaces' })).toBe('Name_with_spaces'); + expect(extractId({ name: 'Name with spaces' })).toBe('NameWithSpaces'); }); }); diff --git a/src/parser/extract-id.ts b/src/parser/extract-id.ts index e47f87a..2e214e2 100644 --- a/src/parser/extract-id.ts +++ b/src/parser/extract-id.ts @@ -4,5 +4,5 @@ export function extractId({ id, name }: { id?: string; name?: string }): string return id; } - return name.replaceAll(/[^a-zA-Z0-9_]/g, '_'); + return name.replace(/\W+(.)/g, (_, chr) => chr.toUpperCase()); }