MCPcopy Create free account
hub / github.com/avoidwork/filesize.js / partial

Function partial

src/filesize.js:216–273  ·  view source on GitHub ↗
({
	bits = false,
	pad = false,
	base = -1,
	round = 2,
	locale = EMPTY,
	separator = EMPTY,
	spacer = SPACE,
	standard = EMPTY,
	output = STRING,
	fullform = false,
	exponent = -1,
	roundingMethod = ROUND,
	precision = 0,
	localeOptions = {},
	symbols = {},
	fullforms = [],
} = {})

Source from the content-addressed store, hash-verified

214 * formatBytes(1536) // "1.5 KiB"
215 */
216export function partial({
217 bits = false,
218 pad = false,
219 base = -1,
220 round = 2,
221 locale = EMPTY,
222 separator = EMPTY,
223 spacer = SPACE,
224 standard = EMPTY,
225 output = STRING,
226 fullform = false,
227 exponent = -1,
228 roundingMethod = ROUND,
229 precision = 0,
230 localeOptions = {},
231 symbols = {},
232 fullforms = [],
233} = {}) {
234 /**
235 * Safely clone an object using structuredClone with JSON fallback.
236 * structuredClone can throw for functions, circular refs, etc.
237 */
238 function safeClone(value) {
239 try {
240 return typeof structuredClone === "function"
241 ? structuredClone(value)
242 : JSON.parse(JSON.stringify(value));
243 } catch {
244 return JSON.parse(JSON.stringify(value));
245 }
246 }
247
248 const cloned = {
249 localeOptions: safeClone(localeOptions),
250 symbols: safeClone(symbols),
251 fullforms: safeClone(fullforms),
252 };
253
254 return (arg) =>
255 filesize(arg, {
256 bits,
257 pad,
258 base,
259 round,
260 locale,
261 localeOptions: cloned.localeOptions,
262 separator,
263 spacer,
264 symbols: cloned.symbols,
265 standard,
266 output,
267 fullform,
268 fullforms: cloned.fullforms,
269 exponent,
270 roundingMethod,
271 precision,
272 });
273}

Calls 2

safeCloneFunction · 0.85
filesizeFunction · 0.85

Tested by

no test coverage detected