UNPKG

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