Skip to content

Commit

Permalink
Merge pull request #116 from dependentmadani/migrate-typescript
Browse files Browse the repository at this point in the history
fix(normalzeData): convert current line to heading fixed
  • Loading branch information
neSpecc authored Jul 13, 2024
2 parents 64a4a02 + e64c3ab commit d5fc14d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "@editorjs/header",
"version": "2.8.6",
"version": "2.8.7",
"keywords": [
"codex editor",
"header",
"heading",
"editor.js",
"editorjs"
],
"description": "Header Tool for Editor.js",
"description": "Heading Tool for Editor.js",
"license": "MIT",
"repository": "https://github.com/editor-js/header",
"files": [
Expand Down
13 changes: 7 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export default class Header {
* @private
*/
isHeaderData(data: any): data is HeaderData {
return (data as HeaderData).text !== undefined && (data as HeaderData).level !== undefined;
return (data as HeaderData).text !== undefined;
}

/**
Expand All @@ -158,13 +158,14 @@ export default class Header {
normalizeData(data: HeaderData | {}): HeaderData {
const newData: HeaderData = { text: '', level: this.defaultLevel.number };

if (!this.isHeaderData(data)) {
return { text: '', level: this.defaultLevel.number};
if (this.isHeaderData(data)) {
newData.text = data.text || '';

if (data.level !== undefined && !isNaN(parseInt(data.level.toString()))) {
newData.level = parseInt(data.level.toString());
}
}

newData.text = data.text || '';
newData.level = parseInt(data.level.toString()) || this.defaultLevel.number;

return newData;
}

Expand Down

0 comments on commit d5fc14d

Please sign in to comment.