UNPKG

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