• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

slikts / tuplerone / 5731886859

pending completion
5731886859

push

github

slikts
feat: add value objects

41 of 42 branches covered (97.62%)

Branch coverage included in aggregate %.

18 of 18 new or added lines in 3 files covered. (100.0%)

88 of 89 relevant lines covered (98.88%)

25.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.3
/src/ValueObject.ts
1
import { getNode, registry } from './graph.ts';
2

3
export function ValueObject<A extends object>(obj: A): DeepReadonly<A> {
4
  if (new.target) {
27!
5
    throw new TypeError('ValueObject is not a constructor');
×
6
  }
7

8
  const entries = Object.entries(obj).map(([key, value]) => {
27✔
9
    if (typeof value === 'object' && value !== null) {
35✔
10
      return [key, ValueObject(value)];
5✔
11
    }
12
    return [key, value];
30✔
13
  });
14
  const path = entries.flat();
27✔
15
  const node = getNode(path);
27✔
16
  const object = node.object?.deref();
27✔
17
  if (!object) {
27✔
18
    const object = Object.freeze(Object.fromEntries(entries)) as DeepReadonly<A>;
13✔
19
    node.object = new WeakRef(object);
13✔
20
    registry.register(object, path);
13✔
21
    return object;
13✔
22
  }
23
  return object as DeepReadonly<A>;
14✔
24
}
25

26
type DeepReadonly<A> = {
27
  readonly [P in keyof A]: A[P] extends object ? DeepReadonly<A[P]> : A[P];
28
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc