MCPcopy Create free account
hub / github.com/arktypeio/arktype / copyDeclared

Function copyDeclared

ark/schema/shared/transform.ts:249–273  ·  view source on GitHub ↗
(
	data: object,
	declared: readonly Key[],
	changes?: readonly unknown[]
)

Source from the content-addressed store, hash-verified

247 * [key, value, output], then without the keys it doesn't declare
248 */
249export const copyDeclared = (
250 data: object,
251 declared: readonly Key[],
252 changes?: readonly unknown[]
253): object => {
254 "use strict"
255 let out = data
256 if (changes) {
257 for (let i = 0; i < changes.length; i += 3) {
258 if (Object.is(changes[i + 2], changes[i + 1])) continue
259 if (out === data) out = copyOf(data)
260 setOwnValue(out, changes[i] as Key, changes[i + 2])
261 }
262 }
263 for (const k of [
264 ...Object.keys(data),
265 ...Object.getOwnPropertySymbols(data)
266 ]) {
267 if (declared.includes(k)) continue
268 if (out === data) out = copyOf(data)
269 delete out[k as never]
270 }
271 if (out !== data) for (const k of declared) keepOwn(out, data, k)
272 return out
273}
274
275// the later output wins a key both changed
276export const mergeTransformed = (

Callers 1

props.test.tsFile · 0.90

Calls 4

keepOwnFunction · 0.85
isMethod · 0.80
copyOfFunction · 0.70
setOwnValueFunction · 0.70

Tested by

no test coverage detected