mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-11-17 21:33:16 +08:00
14 lines
301 B
JavaScript
14 lines
301 B
JavaScript
|
/**
|
||
|
* Returns length of suffix in `string` that should be replaced
|
||
|
* with `newSuffix` to avoid duplication.
|
||
|
*/
|
||
|
export function replacedSuffixLength(string, newSuffix) {
|
||
|
let suffix = newSuffix;
|
||
|
|
||
|
while (!string.endsWith(suffix)) {
|
||
|
suffix = suffix.slice(0, -1);
|
||
|
}
|
||
|
|
||
|
return suffix.length;
|
||
|
}
|