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

Haixing-Hu / js-common-util / 37757a98-aa85-4dfb-bad6-f06a9651a7ac

09 Dec 2023 08:41AM UTC coverage: 57.398% (+1.9%) from 55.49%
37757a98-aa85-4dfb-bad6-f06a9651a7ac

push

circleci

Haixing-Hu
style: fix coding style

264 of 476 branches covered (0.0%)

Branch coverage included in aggregate %.

1 of 2 new or added lines in 2 files covered. (50.0%)

4 existing lines in 4 files now uncovered.

283 of 477 relevant lines covered (59.33%)

13.73 hits per line

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

70.83
/src/to-string.js
1
////////////////////////////////////////////////////////////////////////////////
2
//
3
//    Copyright (c) 2022 - 2023.
4
//    Haixing Hu, Qubit Co. Ltd.
5
//
6
//    All rights reserved.
7
//
8
////////////////////////////////////////////////////////////////////////////////
9
import typeInfo from '@haixing_hu/typeinfo';
10
import jsonStringify from './json-stringify';
11

12
/**
13
 * Convert a value or object to a string representation.
14
 *
15
 * For string, number, and Boolean types, the string form of the value is
16
 * directly given; for other objects, its JSON encoding is given.
17
 *
18
 * @param {any} value
19
 *     The value or object to be converted.
20
 * @param {boolean} beautify
21
 *     Optional, indicating whether to beautify the output JSON string. The
22
 *     default value is `false`.
23
 * @return {string}
24
 *     The string representation of this value or object.
25
 * @author Haixing Hu
26
 */
27
function toString(value, beautify = false) {
15✔
28
  const info = typeInfo(value);
16✔
29
  switch (info.category) {
16!
30
    case 'undefined':       // fall down
31
    case 'null':
32
      return info.category;
2✔
33
    case 'primitive':       //  fall down
34
    case 'function':
35
      return String(value);
6✔
36
    case 'date':
37
      return value.toISOString();
1✔
38
    case 'typed-array':
UNCOV
39
      return `[${String(value)}]`;
×
40
    case 'array':                     // fall down
41
    case 'map':                       // fall down
42
    case 'set':                       // fall down
43
    case 'iterator':                  // fall down
44
    case 'object':                    // fall down
45
    case 'class':
46
      return jsonStringify(value, beautify);
2✔
47
    default:
48
      return info.isBuiltIn ? String(value) : jsonStringify(value, beautify);
5!
49
  }
50
}
51

52
export default toString;
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

© 2026 Coveralls, Inc