UNPKG

1.66 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.createString = void 0;
7
8var _factory = require("../utils/factory");
9
10var _collection = require("../utils/collection");
11
12var _number = require("../utils/number");
13
14var name = 'string';
15var dependencies = ['typed'];
16var createString = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
17 var typed = _ref.typed;
18
19 /**
20 * Create a string or convert any object into a string.
21 * Elements of Arrays and Matrices are processed element wise.
22 *
23 * Syntax:
24 *
25 * math.string(value)
26 *
27 * Examples:
28 *
29 * math.string(4.2) // returns string '4.2'
30 * math.string(math.complex(3, 2) // returns string '3 + 2i'
31 *
32 * const u = math.unit(5, 'km')
33 * math.string(u.to('m')) // returns string '5000 m'
34 *
35 * math.string([true, false]) // returns ['true', 'false']
36 *
37 * See also:
38 *
39 * bignumber, boolean, complex, index, matrix, number, unit
40 *
41 * @param {* | Array | Matrix | null} [value] A value to convert to a string
42 * @return {string | Array | Matrix} The created string
43 */
44 return typed(name, {
45 '': function _() {
46 return '';
47 },
48 number: _number.format,
49 "null": function _null(x) {
50 return 'null';
51 },
52 "boolean": function boolean(x) {
53 return x + '';
54 },
55 string: function string(x) {
56 return x;
57 },
58 'Array | Matrix': function ArrayMatrix(x) {
59 return (0, _collection.deepMap)(x, this);
60 },
61 any: function any(x) {
62 return String(x);
63 }
64 });
65});
66exports.createString = createString;
\No newline at end of file