UNPKG

nbtx

Version:

Jupyter Notebook Translators: Transform Jupyter notebook JSON files (*.ipynb) to and from more compact data structures for use in web applications or other contexts where loading component parts (e.g. images, data, etc.) is preferred.

40 lines (39 loc) 1.38 kB
export const MAX_CHARS = 25000; export const TRUNCATED_CHARS_COUNT = 64; // eslint-disable-next-line @typescript-eslint/no-unused-vars export function DEFAULT_HASH_WARNING(content) { console.warn('nbtx is not using a hashing library to create the hash.\nThe IDs generated are random, please provide a `computeHash` function, for example using "crypto".\nSee nbtx README for more information.'); return `not-a-hash-${Math.random().toString(36).slice(2)}${Math.random().toString(36).slice(2)}`; } export function isNotNull(arg) { return arg != null; } export function ensureSafePath(path) { return path.replace('/', '-'); } /** * Given a list of minified outputs, perform a function on each * * This function traverses into mime outputs which may have multiple outputs included together. */ export function walkOutputs(outputs, func) { outputs.forEach((output) => { if ('data' in output && output.data) { Object.entries(output.data).forEach(([, bundle]) => { func(bundle); }); } else { func(output); } }); } export function ensureString(maybeString, joinWith = '') { if (!maybeString) return ''; if (typeof maybeString === 'string') return maybeString; if (maybeString.join) return maybeString.join(joinWith); return maybeString; }