generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
truncate filenames to fit OS length limit
Closes #6
- Loading branch information
Showing
7 changed files
with
98 additions
and
24 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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Credit: lautis/unicode-substring | ||
* Rewritten for Obsidian mobile functionality. | ||
*/ | ||
|
||
const charAt = (string: string, index: number): string => { | ||
const first = string.charCodeAt(index) | ||
let second | ||
if (first >= 0xd800 && first <= 0xdbff && string.length > index + 1) { | ||
second = string.charCodeAt(index + 1) | ||
if (second >= 0xdc00 && second <= 0xdfff) { | ||
return string.substring(index, index + 2) | ||
} | ||
} | ||
return string[index] | ||
} | ||
|
||
const slice = (string: string, start: number, end: number): string => { | ||
let accumulator = '' | ||
let character | ||
let stringIndex = 0 | ||
let unicodeIndex = 0 | ||
const length = string.length | ||
|
||
while (stringIndex < length) { | ||
character = charAt(string, stringIndex) | ||
if (unicodeIndex >= start && unicodeIndex < end) { | ||
accumulator += character | ||
} | ||
stringIndex += character.length | ||
unicodeIndex += 1 | ||
} | ||
return accumulator | ||
} | ||
|
||
const toNumber = (value: string | number, fallback: number): number => { | ||
if (value === undefined) { | ||
return fallback | ||
} else { | ||
return Number(value) | ||
} | ||
} | ||
|
||
export const unicodeSubstring = ( | ||
string: string, | ||
start: number, | ||
end: number | ||
): string => { | ||
const realStart = toNumber(start, 0) | ||
const realEnd = toNumber(end, string.length) | ||
if (realEnd === realStart) { | ||
return '' | ||
} else if (realEnd > realStart) { | ||
return slice(string, realStart, realEnd) | ||
} else { | ||
return slice(string, realEnd, realStart) | ||
} | ||
} |
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,3 +1,3 @@ | ||
{ | ||
"1.1.3": "0.12.16" | ||
"1.1.4": "0.12.16" | ||
} |
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