-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added 'isEditorContentWithinLimit' utility function (#968)
* Added 'isEditorContentWithinLimit' utility function * Used isNotPresent instead of custom isNilOrEmpty --------- Co-authored-by: Roshan R <[email protected]>
- Loading branch information
1 parent
c6ca916
commit 67d5b99
Showing
3 changed files
with
18 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,27 @@ | ||
import { isNil, isEmpty } from "ramda"; | ||
import { isNotPresent } from "neetocist"; | ||
|
||
import { NON_EMPTY_TAGS } from "./constants"; | ||
|
||
export const isNilOrEmpty = object => isNil(object) || isEmpty(object); | ||
|
||
export const isEditorEmpty = htmlContent => { | ||
if (isNilOrEmpty(htmlContent)) return true; | ||
if (isNotPresent(htmlContent)) return true; | ||
|
||
if (NON_EMPTY_TAGS.some(tag => htmlContent.includes(tag))) return false; | ||
|
||
const element = document.createElement("div"); | ||
element.innerHTML = htmlContent; | ||
const editorIsEmpty = isNilOrEmpty(element.textContent?.trim()); | ||
const editorIsEmpty = isNotPresent(element.textContent?.trim()); | ||
element.remove(); | ||
|
||
return editorIsEmpty; | ||
}; | ||
|
||
export const isEditorContentWithinLimit = (htmlContent, maxLength) => { | ||
if (isNotPresent(htmlContent)) return true; | ||
|
||
const element = document.createElement("div"); | ||
element.innerHTML = htmlContent; | ||
const isLengthWithinLimit = element.textContent.length <= maxLength; | ||
element.remove(); | ||
|
||
return isLengthWithinLimit; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters