diff --git a/packages/core/index.ts b/packages/core/index.ts index fe31eb21..30272f8b 100644 --- a/packages/core/index.ts +++ b/packages/core/index.ts @@ -13,10 +13,8 @@ export { default as nodeInputRule } from './src/inputRules/nodeInputRule' export { default as markInputRule } from './src/inputRules/markInputRule' export { default as markPasteRule } from './src/pasteRules/markPasteRule' -export { default as capitalize } from './src/utils/capitalize' export { default as getSchema } from './src/utils/getSchema' export { default as generateHTML } from './src/utils/generateHTML' export { default as getHTMLFromFragment } from './src/utils/getHTMLFromFragment' export { default as getMarkAttrs } from './src/utils/getMarkAttrs' export { default as mergeAttributes } from './src/utils/mergeAttributes' -export { default as fromString } from './src/utils/fromString' diff --git a/packages/core/src/utils/capitalize.ts b/packages/core/src/utils/capitalize.ts deleted file mode 100644 index 0b9c9d48..00000000 --- a/packages/core/src/utils/capitalize.ts +++ /dev/null @@ -1,3 +0,0 @@ -export default function capitalize(value = ''): string { - return value.charAt(0).toUpperCase() + value.slice(1) -} diff --git a/packages/core/src/utils/fromString.ts b/packages/core/src/utils/fromString.ts index 5371abcc..2ef70c76 100644 --- a/packages/core/src/utils/fromString.ts +++ b/packages/core/src/utils/fromString.ts @@ -1,4 +1,8 @@ export default function fromString(value: any) { + if (typeof value !== 'string') { + return value + } + if (value.match(/^\d*(\.\d+)?$/)) { return Number(value) } diff --git a/tests/cypress/integration/core/capitalize.spec.ts b/tests/cypress/integration/core/capitalize.spec.ts deleted file mode 100644 index 2693a958..00000000 --- a/tests/cypress/integration/core/capitalize.spec.ts +++ /dev/null @@ -1,11 +0,0 @@ -/// - -import { capitalize } from '@tiptap/core' - -describe('capitalize test', () => { - it('capitalize a word', () => { - const capitalized = capitalize('test') - - expect(capitalized).to.eq('Test') - }) -}) diff --git a/tests/cypress/integration/core/example.spec.ts b/tests/cypress/integration/core/example.spec.ts deleted file mode 100644 index 985f70da..00000000 --- a/tests/cypress/integration/core/example.spec.ts +++ /dev/null @@ -1,5 +0,0 @@ -describe('example test', () => { - it('should work', () => { - expect('

Example Text

').to.eq('

Example Text

') - }) -}) diff --git a/tests/cypress/integration/core/fromString.spec.ts b/tests/cypress/integration/core/fromString.spec.ts index 6ecb92bf..2aa6aaa1 100644 --- a/tests/cypress/integration/core/fromString.spec.ts +++ b/tests/cypress/integration/core/fromString.spec.ts @@ -1,41 +1,47 @@ /// -import { fromString } from '@tiptap/core' +import fromString from '@tiptap/core/src/utils/fromString' describe('fromString', () => { - it('parse a string', () => { + it('should return a string', () => { const value = fromString('test') expect(value).to.eq('test') }) - it('parse a number', () => { + it('should convert to a number', () => { const value = fromString('1') expect(value).to.eq(1) }) - it('parse a floating number', () => { + it('should convert to a floating number', () => { const value = fromString('1.2') expect(value).to.eq(1.2) }) - it('parse not a number with exponent', () => { + it('should not convert to a number with exponent', () => { const value = fromString('1e1') expect(value).to.eq('1e1') }) - it('parse a boolean (true)', () => { + it('should convert to true', () => { const value = fromString('true') expect(value).to.eq(true) }) - it('parse a boolean (false)', () => { + it('should convert to false', () => { const value = fromString('false') expect(value).to.eq(false) }) + + it('should return non-strings', () => { + const value = fromString(null) + + expect(value).to.eq(null) + }) })