-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into mh/scatterplot_new
- Loading branch information
Showing
80 changed files
with
4,625 additions
and
1,889 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
Binary file not shown.
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,69 @@ | ||
// NOTE: @dv-usama-ansari: Referenced from https://github.com/parshap/truncate-utf8-bytes/blob/master/lib/truncate.js | ||
import { Buffer } from 'buffer'; | ||
|
||
function isHighSurrogate(codePoint: number) { | ||
return codePoint >= 0xd800 && codePoint <= 0xdbff; | ||
} | ||
|
||
function isLowSurrogate(codePoint: number) { | ||
return codePoint >= 0xdc00 && codePoint <= 0xdfff; | ||
} | ||
|
||
// Truncate string by size in bytes | ||
function truncate(getLength: (str: string) => number, input: string, byteLength: number) { | ||
let curByteLength = 0; | ||
let codePoint = 0; | ||
let segment = ''; | ||
|
||
for (let i = 0; i < input.length; i += 1) { | ||
codePoint = input.charCodeAt(i); | ||
segment = input[i] as string; | ||
|
||
if (isHighSurrogate(codePoint) && isLowSurrogate(input.charCodeAt(i + 1))) { | ||
i += 1; | ||
segment += input[i]; | ||
} | ||
|
||
curByteLength += getLength(segment); | ||
|
||
if (curByteLength === byteLength) { | ||
return input.slice(0, i + 1); | ||
} | ||
if (curByteLength > byteLength) { | ||
return input.slice(0, i - segment.length + 1); | ||
} | ||
} | ||
|
||
return input; | ||
} | ||
|
||
// NOTE: @dv-usama-ansari: Referenced from https://github.com/parshap/truncate-utf8-bytes/blob/master/index.js | ||
const getLength = Buffer.byteLength.bind(Buffer); | ||
const boundTruncate = truncate.bind(null, getLength); | ||
|
||
// NOTE: @dv-usama-ansari: Referenced from https://github.com/parshap/node-sanitize-filename/blob/master/index.js | ||
const illegalRe = /[/?<>\\:*|"]/g; | ||
// eslint-disable-next-line no-control-regex | ||
const controlRe = /[\x00-\x1f\x80-\x9f]/g; | ||
const reservedRe = /^\.+$/; | ||
const windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i; | ||
const windowsTrailingRe = /[. ]+$/; | ||
|
||
function sanitizeHelper(input: string, replacement: string) { | ||
const sanitized = input | ||
.replace(illegalRe, replacement) | ||
.replace(controlRe, replacement) | ||
.replace(reservedRe, replacement) | ||
.replace(windowsReservedRe, replacement) | ||
.replace(windowsTrailingRe, replacement); | ||
return boundTruncate(sanitized, 255); | ||
} | ||
|
||
export function sanitize(input: string, options?: { replacement?: '' }) { | ||
const replacement = options?.replacement ?? ''; | ||
const output = sanitizeHelper(input, replacement); | ||
if (replacement === '') { | ||
return output; | ||
} | ||
return sanitizeHelper(output, ''); | ||
} |
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
Oops, something went wrong.