* Walk `source`; for each key decide what to emit via the small callback. * * The callback returns either * • `undefined` → nothing is copied, or * • `[newKey, newVal]` * * so every public API just supplies a different callback.
( source: S, f: f )
| 824 | * Walk `source`; for each key decide what to emit via the small callback. |
| 825 | * |
| 826 | * The callback returns either |
| 827 | * • `undefined` → nothing is copied, or |
| 828 | * • `[newKey, newVal]` |
| 829 | * |
| 830 | * so every public API just supplies a different callback. |
| 831 | */ |
| 832 | function buildStruct< |
| 833 | S extends object, |
| 834 | f extends (k: keyof S, v: S[keyof S]) => [PropertyKey, unknown] | undefined |
| 835 | >( |
| 836 | source: S, |
| 837 | f: f |
| 838 | ): any { |
| 839 | const out: Record<PropertyKey, unknown> = {} |
| 840 | for (const k of Reflect.ownKeys(source) as Array<keyof S>) { |
| 841 | if (!Object.prototype.propertyIsEnumerable.call(source, k)) continue |
| 842 | const res = f(k, source[k]) |
| 843 | if (res) { |
| 844 | const [nk, nv] = res |
| 845 | InternalRecord.assignProperty(out, nk, nv) |
| 846 | } |