Skip to content

Commit

Permalink
refactor: #74 some refactors
Browse files Browse the repository at this point in the history
- use '' single quotes for non-localizable strings
- use const instead of let where required
- use == instead of === where required
  • Loading branch information
dilshans2k committed Apr 26, 2024
1 parent ad52c9b commit 0f1ffb1
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/drafty.js
Original file line number Diff line number Diff line change
Expand Up @@ -2222,7 +2222,7 @@ function draftyToTree(doc) {
}
});

const graphemes = getGraphemesFromString(txt)
const graphemes = getGraphemesFromString(txt);
let tree = spansToTree({}, graphemes, 0, graphemes.length, spans);

// Flatten tree nodes.
Expand Down Expand Up @@ -2278,7 +2278,7 @@ function spansToTree(parent, graphemes, start, end, spans) {
addNode(parent, {
text: graphemes.slice(start, end)
.map(segment => segment.segment)
.join("")
.join('')
});
}
return parent;
Expand All @@ -2302,7 +2302,7 @@ function spansToTree(parent, graphemes, start, end, spans) {
addNode(parent, {
text: graphemes.slice(start, span.start)
.map(segment => segment.segment)
.join("")
.join('')
});
start = span.start;
}
Expand Down Expand Up @@ -2345,7 +2345,7 @@ function spansToTree(parent, graphemes, start, end, spans) {
text: graphemes
.slice(start, end)
.map((segment) => segment.segment)
.join("")
.join('')
});
}

Expand Down Expand Up @@ -2500,7 +2500,7 @@ function shortenTree(tree, limit, tail) {
node.text = graphemes
.slice(0, limit)
.map((segment) => segment.segment)
.join("") + tail;
.join('') + tail;
limit = -1;
} else {
limit -= graphemes.length;
Expand Down Expand Up @@ -2681,20 +2681,20 @@ function copyEntData(data, light, allow) {

// Returns true if object is empty, if undefined returns true
function isEmptyObject(obj) {
return Object.keys(obj ?? {}).length === 0;
return Object.keys(obj ?? {}).length == 0;
};


// Returns an array(len equal to og string) such that each index
// denotes the position of char in string in a grapheme array(created from that string)
// Eg: string: "Hi👋🏼Hi" -> [0,1,2,2,2,2,3,4]
function getGraphemeIndices(graphemes) {
let result = [];
const result = [];
let graphemeIndex = 0;
let charIndex = 0;

// Iterate over the grapheme clusters
for (let {
for (const {
segment
}
of graphemes) {
Expand Down

0 comments on commit 0f1ffb1

Please sign in to comment.