MCPcopy
hub / github.com/vitejs/vite / flattenId

Function flattenId

packages/vite/src/node/utils.ts:72–86  ·  view source on GitHub ↗
(id: string)

Source from the content-addressed store, hash-verified

70const invalidUrlPathCharRE = /[\u0000-\u001F"#$%&*+,:;<=>?[\]^`{|}\u007F]/g
71const replaceNestedIdRE = /\s*>\s*/g
72export const flattenId = (id: string): string => {
73 const flatId = limitFlattenIdLength(
74 id
75 .replaceAll(/_+/g, '$&__')
76 .replaceAll('/', '_')
77 .replaceAll('.', '__')
78 .replace(replaceNestedIdRE, '_n_')
79 // replace any characters that will be replaced by sanitizeFileName
80 .replace(
81 invalidUrlPathCharRE,
82 (c) => '_0' + c.charCodeAt(0).toString(16) + '_',
83 ),
84 )
85 return flatId
86}
87
88const FLATTEN_ID_HASH_LENGTH = 8
89const FLATTEN_ID_MAX_FILE_LENGTH = 170

Callers 5

utils.spec.tsFile · 0.90
runOptimizeDepsFunction · 0.90
getOptimizedDepPathFunction · 0.90
resolveEntryFunction · 0.90

Calls 1

limitFlattenIdLengthFunction · 0.85

Tested by

no test coverage detected