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

realm / realm-js / 7685289785

28 Jan 2024 11:05AM UTC coverage: 85.346%. Remained the same
7685289785

Pull #6379

github

web-flow
Update all of typescript-eslint to version 6.18.1
Pull Request #6379: Update all of typescript-eslint 5.62.0 → 6.18.1 (major)

942 of 1164 branches covered (0.0%)

Branch coverage included in aggregate %.

2372 of 2719 relevant lines covered (87.24%)

1015.97 hits per line

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

6.67
/packages/realm/src/platform/node/custom-inspect.ts
1
////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2023 Realm Inc.
4
//
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
//
17
////////////////////////////////////////////////////////////////////////////
18
import { InspectOptionsStylized, inspect } from "node:util";
19

20
import { Collection, Dictionary, List, RealmObject, RealmSet, Results } from "../../internal";
21

22
type CustomInspectFunction<T> = (this: T, depth: number, options: InspectOptionsStylized) => void;
23

24
function injectInspect<T extends object>(constructor: { prototype: T }, customInspect: CustomInspectFunction<T>) {
25
  Object.assign(constructor.prototype, { [inspect.custom]: customInspect });
2✔
26
}
27

28
function constructorName(value: object) {
29
  if (value instanceof RealmObject) {
×
30
    return value.objectSchema().name;
×
31
  } else if (value instanceof RealmSet) {
×
32
    return "Realm.Set";
×
33
  } else if (value instanceof List) {
×
34
    return "Realm.List";
×
35
  } else if (value instanceof Dictionary) {
×
36
    return "Realm.Dictionary";
×
37
  } else if (value instanceof Results) {
×
38
    return "Realm.Results";
×
39
  } else {
40
    return value.constructor.name;
×
41
  }
42
}
43

44
function isIterable<T>(value: object): value is Iterable<T> {
45
  if (value instanceof Dictionary) {
×
46
    return false;
×
47
  } else if (Symbol.iterator in value) {
×
48
    return true;
×
49
  } else {
50
    return false;
×
51
  }
52
}
53

54
function defaultInspector<T extends object>(this: T, depth: number, options: InspectOptionsStylized) {
55
  const name = constructorName(this);
×
56
  if (depth === -1) {
×
57
    if (options.colors) {
×
58
      return options.stylize(`[${name}]`, "special");
×
59
    } else {
60
      return `[${name}]`;
×
61
    }
62
  } else {
63
    return `${name} ${inspect(isIterable(this) ? [...this] : { ...this }, options.showHidden, depth, options.colors)}`;
×
64
  }
65
}
66

67
injectInspect(RealmObject, defaultInspector);
1✔
68
injectInspect(Collection, defaultInspector);
1✔
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