MCPcopy
hub / github.com/directus/directus / getCompressed

Function getCompressed

packages/utils/shared/compress.ts:160–180  ·  view source on GitHub ↗
(part: Token | NestedToken)

Source from the content-addressed store, hash-verified

158 const ast = getAst(obj);
159
160 const getCompressed = (part: Token | NestedToken) => {
161 if (Array.isArray(part)) {
162 let compressed: string = part.shift() as '@' | '$';
163 part.forEach((subPart) => (compressed += getCompressed(subPart as Token) + '|'));
164 if (compressed.endsWith('|')) compressed = compressed.slice(0, -1);
165 return compressed + ']';
166 }
167
168 const { type, index } = part;
169
170 switch (type) {
171 case Types.STRING:
172 return to36(index);
173 case Types.INTEGER:
174 return to36(strings.size + index);
175 case Types.FLOAT:
176 return to36(strings.size + integers.size + index);
177 default:
178 return index;
179 }
180 };
181
182 let compressed = mapToSortedArray(strings).join('|');
183 compressed += '^' + mapToSortedArray(integers).join('|');

Callers 1

compressFunction · 0.85

Calls 2

to36Function · 0.85
sliceMethod · 0.80

Tested by

no test coverage detected