@ohos-ports/stdlib-complex-real 0.0.0-stage → 0.2.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. package/LICENSE +177 -0
  2. package/NOTICE +1 -0
  3. package/README.md +320 -2
  4. package/SECURITY.md +5 -0
  5. package/dist/index.d.ts +3 -0
  6. package/dist/index.js +5 -0
  7. package/dist/index.js.map +7 -0
  8. package/docs/types/index.d.ts +44 -0
  9. package/include/stdlib/complex/real.h +40 -0
  10. package/lib/index.js +43 -0
  11. package/lib/main.js +42 -0
  12. package/manifest.json +40 -0
  13. package/node_modules/@stdlib/array-float32/LICENSE +177 -0
  14. package/node_modules/@stdlib/array-float32/NOTICE +1 -0
  15. package/node_modules/@stdlib/array-float32/README.md +1577 -0
  16. package/node_modules/@stdlib/array-float32/SECURITY.md +5 -0
  17. package/node_modules/@stdlib/array-float32/dist/index.d.ts +3 -0
  18. package/node_modules/@stdlib/array-float32/dist/index.js +19 -0
  19. package/node_modules/@stdlib/array-float32/dist/index.js.map +7 -0
  20. package/node_modules/@stdlib/array-float32/docs/types/index.d.ts +26 -0
  21. package/node_modules/@stdlib/array-float32/lib/index.js +52 -0
  22. package/node_modules/@stdlib/array-float32/lib/main.js +28 -0
  23. package/node_modules/@stdlib/array-float32/lib/polyfill.js +37 -0
  24. package/node_modules/@stdlib/array-float32/package.json +72 -0
  25. package/node_modules/@stdlib/assert-has-float32array-support/LICENSE +177 -0
  26. package/node_modules/@stdlib/assert-has-float32array-support/NOTICE +1 -0
  27. package/node_modules/@stdlib/assert-has-float32array-support/README.md +187 -0
  28. package/node_modules/@stdlib/assert-has-float32array-support/SECURITY.md +5 -0
  29. package/node_modules/@stdlib/assert-has-float32array-support/dist/index.d.ts +3 -0
  30. package/node_modules/@stdlib/assert-has-float32array-support/dist/index.js +7 -0
  31. package/node_modules/@stdlib/assert-has-float32array-support/dist/index.js.map +7 -0
  32. package/node_modules/@stdlib/assert-has-float32array-support/docs/types/index.d.ts +35 -0
  33. package/node_modules/@stdlib/assert-has-float32array-support/lib/float32array.js +28 -0
  34. package/node_modules/@stdlib/assert-has-float32array-support/lib/index.js +40 -0
  35. package/node_modules/@stdlib/assert-has-float32array-support/lib/main.js +65 -0
  36. package/node_modules/@stdlib/assert-has-float32array-support/package.json +77 -0
  37. package/node_modules/@stdlib/assert-has-own-property/LICENSE +177 -0
  38. package/node_modules/@stdlib/assert-has-own-property/NOTICE +1 -0
  39. package/node_modules/@stdlib/assert-has-own-property/README.md +263 -0
  40. package/node_modules/@stdlib/assert-has-own-property/SECURITY.md +5 -0
  41. package/node_modules/@stdlib/assert-has-own-property/dist/index.d.ts +3 -0
  42. package/node_modules/@stdlib/assert-has-own-property/dist/index.js +5 -0
  43. package/node_modules/@stdlib/assert-has-own-property/dist/index.js.map +7 -0
  44. package/node_modules/@stdlib/assert-has-own-property/docs/types/index.d.ts +49 -0
  45. package/node_modules/@stdlib/assert-has-own-property/lib/index.js +47 -0
  46. package/node_modules/@stdlib/assert-has-own-property/lib/main.js +64 -0
  47. package/node_modules/@stdlib/assert-has-own-property/package.json +73 -0
  48. package/node_modules/@stdlib/assert-has-symbol-support/LICENSE +177 -0
  49. package/node_modules/@stdlib/assert-has-symbol-support/NOTICE +1 -0
  50. package/node_modules/@stdlib/assert-has-symbol-support/README.md +193 -0
  51. package/node_modules/@stdlib/assert-has-symbol-support/SECURITY.md +5 -0
  52. package/node_modules/@stdlib/assert-has-symbol-support/dist/index.d.ts +3 -0
  53. package/node_modules/@stdlib/assert-has-symbol-support/dist/index.js +5 -0
  54. package/node_modules/@stdlib/assert-has-symbol-support/dist/index.js.map +7 -0
  55. package/node_modules/@stdlib/assert-has-symbol-support/docs/types/index.d.ts +35 -0
  56. package/node_modules/@stdlib/assert-has-symbol-support/lib/index.js +40 -0
  57. package/node_modules/@stdlib/assert-has-symbol-support/lib/main.js +42 -0
  58. package/node_modules/@stdlib/assert-has-symbol-support/package.json +72 -0
  59. package/node_modules/@stdlib/assert-has-tostringtag-support/LICENSE +177 -0
  60. package/node_modules/@stdlib/assert-has-tostringtag-support/NOTICE +1 -0
  61. package/node_modules/@stdlib/assert-has-tostringtag-support/README.md +187 -0
  62. package/node_modules/@stdlib/assert-has-tostringtag-support/SECURITY.md +5 -0
  63. package/node_modules/@stdlib/assert-has-tostringtag-support/dist/index.d.ts +3 -0
  64. package/node_modules/@stdlib/assert-has-tostringtag-support/dist/index.js +5 -0
  65. package/node_modules/@stdlib/assert-has-tostringtag-support/dist/index.js.map +7 -0
  66. package/node_modules/@stdlib/assert-has-tostringtag-support/docs/types/index.d.ts +35 -0
  67. package/node_modules/@stdlib/assert-has-tostringtag-support/lib/index.js +40 -0
  68. package/node_modules/@stdlib/assert-has-tostringtag-support/lib/main.js +49 -0
  69. package/node_modules/@stdlib/assert-has-tostringtag-support/package.json +78 -0
  70. package/node_modules/@stdlib/assert-is-float32array/LICENSE +177 -0
  71. package/node_modules/@stdlib/assert-is-float32array/NOTICE +1 -0
  72. package/node_modules/@stdlib/assert-is-float32array/README.md +229 -0
  73. package/node_modules/@stdlib/assert-is-float32array/SECURITY.md +5 -0
  74. package/node_modules/@stdlib/assert-is-float32array/dist/index.d.ts +3 -0
  75. package/node_modules/@stdlib/assert-is-float32array/dist/index.js +5 -0
  76. package/node_modules/@stdlib/assert-is-float32array/dist/index.js.map +7 -0
  77. package/node_modules/@stdlib/assert-is-float32array/docs/types/index.d.ts +42 -0
  78. package/node_modules/@stdlib/assert-is-float32array/lib/index.js +44 -0
  79. package/node_modules/@stdlib/assert-is-float32array/lib/main.js +59 -0
  80. package/node_modules/@stdlib/assert-is-float32array/package.json +81 -0
  81. package/node_modules/@stdlib/assert-is-number/LICENSE +177 -0
  82. package/node_modules/@stdlib/assert-is-number/NOTICE +1 -0
  83. package/node_modules/@stdlib/assert-is-number/README.md +231 -0
  84. package/node_modules/@stdlib/assert-is-number/SECURITY.md +5 -0
  85. package/node_modules/@stdlib/assert-is-number/dist/index.d.ts +3 -0
  86. package/node_modules/@stdlib/assert-is-number/dist/index.js +13 -0
  87. package/node_modules/@stdlib/assert-is-number/dist/index.js.map +7 -0
  88. package/node_modules/@stdlib/assert-is-number/docs/types/index.d.ts +121 -0
  89. package/node_modules/@stdlib/assert-is-number/lib/index.js +79 -0
  90. package/node_modules/@stdlib/assert-is-number/lib/main.js +58 -0
  91. package/node_modules/@stdlib/assert-is-number/lib/object.js +66 -0
  92. package/node_modules/@stdlib/assert-is-number/lib/primitive.js +46 -0
  93. package/node_modules/@stdlib/assert-is-number/lib/tostring.js +34 -0
  94. package/node_modules/@stdlib/assert-is-number/lib/try2serialize.js +47 -0
  95. package/node_modules/@stdlib/assert-is-number/package.json +80 -0
  96. package/node_modules/@stdlib/complex-float32/LICENSE +177 -0
  97. package/node_modules/@stdlib/complex-float32/NOTICE +1 -0
  98. package/node_modules/@stdlib/complex-float32/README.md +629 -0
  99. package/node_modules/@stdlib/complex-float32/SECURITY.md +5 -0
  100. package/node_modules/@stdlib/complex-float32/dist/index.d.ts +3 -0
  101. package/node_modules/@stdlib/complex-float32/dist/index.js +9 -0
  102. package/node_modules/@stdlib/complex-float32/dist/index.js.map +7 -0
  103. package/node_modules/@stdlib/complex-float32/docs/types/index.d.ts +111 -0
  104. package/node_modules/@stdlib/complex-float32/lib/index.js +40 -0
  105. package/node_modules/@stdlib/complex-float32/lib/main.js +159 -0
  106. package/node_modules/@stdlib/complex-float32/lib/tojson.js +39 -0
  107. package/node_modules/@stdlib/complex-float32/lib/tostring.js +42 -0
  108. package/node_modules/@stdlib/complex-float32/manifest.json +38 -0
  109. package/node_modules/@stdlib/complex-float32/package.json +76 -0
  110. package/node_modules/@stdlib/complex-float64/LICENSE +177 -0
  111. package/node_modules/@stdlib/complex-float64/NOTICE +1 -0
  112. package/node_modules/@stdlib/complex-float64/README.md +699 -0
  113. package/node_modules/@stdlib/complex-float64/SECURITY.md +5 -0
  114. package/node_modules/@stdlib/complex-float64/dist/index.d.ts +3 -0
  115. package/node_modules/@stdlib/complex-float64/dist/index.js +9 -0
  116. package/node_modules/@stdlib/complex-float64/dist/index.js.map +7 -0
  117. package/node_modules/@stdlib/complex-float64/docs/types/index.d.ts +111 -0
  118. package/node_modules/@stdlib/complex-float64/lib/index.js +40 -0
  119. package/node_modules/@stdlib/complex-float64/lib/main.js +158 -0
  120. package/node_modules/@stdlib/complex-float64/lib/tojson.js +39 -0
  121. package/node_modules/@stdlib/complex-float64/lib/tostring.js +42 -0
  122. package/node_modules/@stdlib/complex-float64/manifest.json +40 -0
  123. package/node_modules/@stdlib/complex-float64/package.json +75 -0
  124. package/node_modules/@stdlib/constants-float64-pinf/LICENSE +177 -0
  125. package/node_modules/@stdlib/constants-float64-pinf/NOTICE +1 -0
  126. package/node_modules/@stdlib/constants-float64-pinf/README.md +238 -0
  127. package/node_modules/@stdlib/constants-float64-pinf/SECURITY.md +5 -0
  128. package/node_modules/@stdlib/constants-float64-pinf/dist/index.d.ts +3 -0
  129. package/node_modules/@stdlib/constants-float64-pinf/dist/index.js +3 -0
  130. package/node_modules/@stdlib/constants-float64-pinf/dist/index.js.map +7 -0
  131. package/node_modules/@stdlib/constants-float64-pinf/docs/types/index.d.ts +33 -0
  132. package/node_modules/@stdlib/constants-float64-pinf/lib/index.js +56 -0
  133. package/node_modules/@stdlib/constants-float64-pinf/manifest.json +36 -0
  134. package/node_modules/@stdlib/constants-float64-pinf/package.json +71 -0
  135. package/node_modules/@stdlib/error-tools-fmtprodmsg/LICENSE +177 -0
  136. package/node_modules/@stdlib/error-tools-fmtprodmsg/NOTICE +1 -0
  137. package/node_modules/@stdlib/error-tools-fmtprodmsg/README.md +182 -0
  138. package/node_modules/@stdlib/error-tools-fmtprodmsg/SECURITY.md +5 -0
  139. package/node_modules/@stdlib/error-tools-fmtprodmsg/dist/index.d.ts +3 -0
  140. package/node_modules/@stdlib/error-tools-fmtprodmsg/dist/index.js +5 -0
  141. package/node_modules/@stdlib/error-tools-fmtprodmsg/dist/index.js.map +7 -0
  142. package/node_modules/@stdlib/error-tools-fmtprodmsg/docs/types/index.d.ts +39 -0
  143. package/node_modules/@stdlib/error-tools-fmtprodmsg/lib/index.js +40 -0
  144. package/node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js +48 -0
  145. package/node_modules/@stdlib/error-tools-fmtprodmsg/package.json +70 -0
  146. package/node_modules/@stdlib/number-ctor/LICENSE +177 -0
  147. package/node_modules/@stdlib/number-ctor/NOTICE +1 -0
  148. package/node_modules/@stdlib/number-ctor/README.md +212 -0
  149. package/node_modules/@stdlib/number-ctor/SECURITY.md +5 -0
  150. package/node_modules/@stdlib/number-ctor/dist/index.d.ts +3 -0
  151. package/node_modules/@stdlib/number-ctor/dist/index.js +5 -0
  152. package/node_modules/@stdlib/number-ctor/dist/index.js.map +7 -0
  153. package/node_modules/@stdlib/number-ctor/docs/types/index.d.ts +30 -0
  154. package/node_modules/@stdlib/number-ctor/lib/index.js +40 -0
  155. package/node_modules/@stdlib/number-ctor/lib/main.js +23 -0
  156. package/node_modules/@stdlib/number-ctor/package.json +62 -0
  157. package/node_modules/@stdlib/number-float64-base-to-float32/LICENSE +177 -0
  158. package/node_modules/@stdlib/number-float64-base-to-float32/NOTICE +1 -0
  159. package/node_modules/@stdlib/number-float64-base-to-float32/README.md +191 -0
  160. package/node_modules/@stdlib/number-float64-base-to-float32/SECURITY.md +5 -0
  161. package/node_modules/@stdlib/number-float64-base-to-float32/dist/index.d.ts +3 -0
  162. package/node_modules/@stdlib/number-float64-base-to-float32/dist/index.js +19 -0
  163. package/node_modules/@stdlib/number-float64-base-to-float32/dist/index.js.map +7 -0
  164. package/node_modules/@stdlib/number-float64-base-to-float32/docs/types/index.d.ts +36 -0
  165. package/node_modules/@stdlib/number-float64-base-to-float32/lib/index.js +51 -0
  166. package/node_modules/@stdlib/number-float64-base-to-float32/lib/main.js +28 -0
  167. package/node_modules/@stdlib/number-float64-base-to-float32/lib/polyfill.js +51 -0
  168. package/node_modules/@stdlib/number-float64-base-to-float32/package.json +76 -0
  169. package/node_modules/@stdlib/string-base-format-interpolate/LICENSE +177 -0
  170. package/node_modules/@stdlib/string-base-format-interpolate/NOTICE +1 -0
  171. package/node_modules/@stdlib/string-base-format-interpolate/README.md +219 -0
  172. package/node_modules/@stdlib/string-base-format-interpolate/SECURITY.md +5 -0
  173. package/node_modules/@stdlib/string-base-format-interpolate/dist/index.d.ts +3 -0
  174. package/node_modules/@stdlib/string-base-format-interpolate/dist/index.js +17 -0
  175. package/node_modules/@stdlib/string-base-format-interpolate/dist/index.js.map +7 -0
  176. package/node_modules/@stdlib/string-base-format-interpolate/docs/types/index.d.ts +71 -0
  177. package/node_modules/@stdlib/string-base-format-interpolate/lib/format_double.js +103 -0
  178. package/node_modules/@stdlib/string-base-format-interpolate/lib/format_integer.js +115 -0
  179. package/node_modules/@stdlib/string-base-format-interpolate/lib/index.js +41 -0
  180. package/node_modules/@stdlib/string-base-format-interpolate/lib/is_number.js +46 -0
  181. package/node_modules/@stdlib/string-base-format-interpolate/lib/is_string.js +42 -0
  182. package/node_modules/@stdlib/string-base-format-interpolate/lib/main.js +243 -0
  183. package/node_modules/@stdlib/string-base-format-interpolate/lib/space_pad.js +65 -0
  184. package/node_modules/@stdlib/string-base-format-interpolate/lib/zero_pad.js +84 -0
  185. package/node_modules/@stdlib/string-base-format-interpolate/package.json +71 -0
  186. package/node_modules/@stdlib/string-base-format-tokenize/LICENSE +177 -0
  187. package/node_modules/@stdlib/string-base-format-tokenize/NOTICE +1 -0
  188. package/node_modules/@stdlib/string-base-format-tokenize/README.md +203 -0
  189. package/node_modules/@stdlib/string-base-format-tokenize/SECURITY.md +5 -0
  190. package/node_modules/@stdlib/string-base-format-tokenize/dist/index.d.ts +3 -0
  191. package/node_modules/@stdlib/string-base-format-tokenize/dist/index.js +5 -0
  192. package/node_modules/@stdlib/string-base-format-tokenize/dist/index.js.map +7 -0
  193. package/node_modules/@stdlib/string-base-format-tokenize/docs/types/index.d.ts +68 -0
  194. package/node_modules/@stdlib/string-base-format-tokenize/lib/index.js +41 -0
  195. package/node_modules/@stdlib/string-base-format-tokenize/lib/main.js +95 -0
  196. package/node_modules/@stdlib/string-base-format-tokenize/package.json +69 -0
  197. package/node_modules/@stdlib/string-format/LICENSE +177 -0
  198. package/node_modules/@stdlib/string-format/NOTICE +1 -0
  199. package/node_modules/@stdlib/string-format/README.md +341 -0
  200. package/node_modules/@stdlib/string-format/SECURITY.md +5 -0
  201. package/node_modules/@stdlib/string-format/dist/index.d.ts +3 -0
  202. package/node_modules/@stdlib/string-format/dist/index.js +7 -0
  203. package/node_modules/@stdlib/string-format/dist/index.js.map +7 -0
  204. package/node_modules/@stdlib/string-format/docs/types/index.d.ts +42 -0
  205. package/node_modules/@stdlib/string-format/lib/index.js +43 -0
  206. package/node_modules/@stdlib/string-format/lib/is_string.js +42 -0
  207. package/node_modules/@stdlib/string-format/lib/main.js +64 -0
  208. package/node_modules/@stdlib/string-format/package.json +72 -0
  209. package/node_modules/@stdlib/symbol-ctor/LICENSE +177 -0
  210. package/node_modules/@stdlib/symbol-ctor/NOTICE +1 -0
  211. package/node_modules/@stdlib/symbol-ctor/README.md +234 -0
  212. package/node_modules/@stdlib/symbol-ctor/SECURITY.md +5 -0
  213. package/node_modules/@stdlib/symbol-ctor/dist/index.d.ts +3 -0
  214. package/node_modules/@stdlib/symbol-ctor/dist/index.js +5 -0
  215. package/node_modules/@stdlib/symbol-ctor/dist/index.js.map +7 -0
  216. package/node_modules/@stdlib/symbol-ctor/docs/types/index.d.ts +34 -0
  217. package/node_modules/@stdlib/symbol-ctor/lib/index.js +40 -0
  218. package/node_modules/@stdlib/symbol-ctor/lib/main.js +28 -0
  219. package/node_modules/@stdlib/symbol-ctor/package.json +62 -0
  220. package/node_modules/@stdlib/types/LICENSE +177 -0
  221. package/node_modules/@stdlib/types/NOTICE +1 -0
  222. package/node_modules/@stdlib/types/README.md +212 -0
  223. package/node_modules/@stdlib/types/SECURITY.md +5 -0
  224. package/node_modules/@stdlib/types/index.d.ts +3923 -0
  225. package/node_modules/@stdlib/types/lib/browser.js +28 -0
  226. package/node_modules/@stdlib/types/lib/index.js +39 -0
  227. package/node_modules/@stdlib/types/lib/main.js +40 -0
  228. package/node_modules/@stdlib/types/package.json +67 -0
  229. package/node_modules/@stdlib/types/test.ts +734 -0
  230. package/node_modules/@stdlib/utils-define-nonenumerable-read-only-property/LICENSE +177 -0
  231. package/node_modules/@stdlib/utils-define-nonenumerable-read-only-property/NOTICE +1 -0
  232. package/node_modules/@stdlib/utils-define-nonenumerable-read-only-property/README.md +216 -0
  233. package/node_modules/@stdlib/utils-define-nonenumerable-read-only-property/SECURITY.md +5 -0
  234. package/node_modules/@stdlib/utils-define-nonenumerable-read-only-property/dist/index.d.ts +3 -0
  235. package/node_modules/@stdlib/utils-define-nonenumerable-read-only-property/dist/index.js +31 -0
  236. package/node_modules/@stdlib/utils-define-nonenumerable-read-only-property/dist/index.js.map +7 -0
  237. package/node_modules/@stdlib/utils-define-nonenumerable-read-only-property/dist/main.js +58 -0
  238. package/node_modules/@stdlib/utils-define-nonenumerable-read-only-property/docs/types/index.d.ts +52 -0
  239. package/node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/index.js +47 -0
  240. package/node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/main.js +58 -0
  241. package/node_modules/@stdlib/utils-define-nonenumerable-read-only-property/package.json +92 -0
  242. package/node_modules/@stdlib/utils-define-property/LICENSE +177 -0
  243. package/node_modules/@stdlib/utils-define-property/NOTICE +1 -0
  244. package/node_modules/@stdlib/utils-define-property/README.md +228 -0
  245. package/node_modules/@stdlib/utils-define-property/SECURITY.md +5 -0
  246. package/node_modules/@stdlib/utils-define-property/dist/index.d.ts +3 -0
  247. package/node_modules/@stdlib/utils-define-property/dist/index.js +36 -0
  248. package/node_modules/@stdlib/utils-define-property/dist/index.js.map +7 -0
  249. package/node_modules/@stdlib/utils-define-property/docs/types/index.d.ts +52 -0
  250. package/node_modules/@stdlib/utils-define-property/lib/builtin.js +61 -0
  251. package/node_modules/@stdlib/utils-define-property/lib/define_property.js +28 -0
  252. package/node_modules/@stdlib/utils-define-property/lib/has_define_property_support.js +51 -0
  253. package/node_modules/@stdlib/utils-define-property/lib/index.js +58 -0
  254. package/node_modules/@stdlib/utils-define-property/lib/polyfill.js +122 -0
  255. package/node_modules/@stdlib/utils-define-property/package.json +74 -0
  256. package/node_modules/@stdlib/utils-native-class/LICENSE +177 -0
  257. package/node_modules/@stdlib/utils-native-class/NOTICE +1 -0
  258. package/node_modules/@stdlib/utils-native-class/README.md +349 -0
  259. package/node_modules/@stdlib/utils-native-class/SECURITY.md +5 -0
  260. package/node_modules/@stdlib/utils-native-class/dist/index.d.ts +3 -0
  261. package/node_modules/@stdlib/utils-native-class/dist/index.js +11 -0
  262. package/node_modules/@stdlib/utils-native-class/dist/index.js.map +7 -0
  263. package/node_modules/@stdlib/utils-native-class/docs/types/index.d.ts +51 -0
  264. package/node_modules/@stdlib/utils-native-class/lib/index.js +61 -0
  265. package/node_modules/@stdlib/utils-native-class/lib/main.js +56 -0
  266. package/node_modules/@stdlib/utils-native-class/lib/polyfill.js +81 -0
  267. package/node_modules/@stdlib/utils-native-class/lib/tostring.js +28 -0
  268. package/node_modules/@stdlib/utils-native-class/lib/tostringtag.js +33 -0
  269. package/node_modules/@stdlib/utils-native-class/package.json +83 -0
  270. package/package.json +71 -3
  271. package/src/main.c +42 -0
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2022 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ // NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.
24
+ var abs = Math.abs; // eslint-disable-line stdlib/no-builtin-math
25
+ var lowercase = String.prototype.toLowerCase;
26
+ var uppercase = String.prototype.toUpperCase;
27
+ var replace = String.prototype.replace;
28
+
29
+
30
+ // VARIABLES //
31
+
32
+ var RE_EXP_POS_DIGITS = /e\+(\d)$/;
33
+ var RE_EXP_NEG_DIGITS = /e-(\d)$/;
34
+ var RE_ONLY_DIGITS = /^(\d+)$/;
35
+ var RE_DIGITS_BEFORE_EXP = /^(\d+)e/;
36
+ var RE_TRAILING_PERIOD_ZERO = /\.0$/;
37
+ var RE_PERIOD_ZERO_EXP = /\.0*e/;
38
+ var RE_ZERO_BEFORE_EXP = /(\..*[^0])0*e/;
39
+
40
+
41
+ // MAIN //
42
+
43
+ /**
44
+ * Formats a token object argument as a floating-point number.
45
+ *
46
+ * @private
47
+ * @param {number} f - parsed number
48
+ * @param {Object} token - token object
49
+ * @throws {Error} must provide a valid floating-point number
50
+ * @returns {string} formatted token argument
51
+ */
52
+ function formatDouble( f, token ) {
53
+ var digits;
54
+ var out;
55
+
56
+ switch ( token.specifier ) {
57
+ case 'e':
58
+ case 'E':
59
+ out = f.toExponential( token.precision );
60
+ break;
61
+ case 'f':
62
+ case 'F':
63
+ out = f.toFixed( token.precision );
64
+ break;
65
+ case 'g':
66
+ case 'G':
67
+ if ( abs( f ) < 0.0001 ) {
68
+ digits = token.precision;
69
+ if ( digits > 0 ) {
70
+ digits -= 1;
71
+ }
72
+ out = f.toExponential( digits );
73
+ } else {
74
+ out = f.toPrecision( token.precision );
75
+ }
76
+ if ( !token.alternate ) {
77
+ out = replace.call( out, RE_ZERO_BEFORE_EXP, '$1e' );
78
+ out = replace.call( out, RE_PERIOD_ZERO_EXP, 'e' );
79
+ out = replace.call( out, RE_TRAILING_PERIOD_ZERO, '' );
80
+ }
81
+ break;
82
+ default:
83
+ throw new Error( 'invalid double notation. Value: ' + token.specifier );
84
+ }
85
+ out = replace.call( out, RE_EXP_POS_DIGITS, 'e+0$1' );
86
+ out = replace.call( out, RE_EXP_NEG_DIGITS, 'e-0$1' );
87
+ if ( token.alternate ) {
88
+ out = replace.call( out, RE_ONLY_DIGITS, '$1.' );
89
+ out = replace.call( out, RE_DIGITS_BEFORE_EXP, '$1.e' );
90
+ }
91
+ if ( f >= 0 && token.sign ) {
92
+ out = token.sign + out;
93
+ }
94
+ out = ( token.specifier === uppercase.call( token.specifier ) ) ?
95
+ uppercase.call( out ) :
96
+ lowercase.call( out );
97
+ return out;
98
+ }
99
+
100
+
101
+ // EXPORTS //
102
+
103
+ module.exports = formatDouble;
@@ -0,0 +1,115 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2022 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var isNumber = require( './is_number.js' );
24
+ var zeroPad = require( './zero_pad.js' );
25
+
26
+ // NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.
27
+ var lowercase = String.prototype.toLowerCase;
28
+ var uppercase = String.prototype.toUpperCase;
29
+
30
+
31
+ // MAIN //
32
+
33
+ /**
34
+ * Formats a token object argument as an integer.
35
+ *
36
+ * @private
37
+ * @param {Object} token - token object
38
+ * @throws {Error} must provide a valid integer
39
+ * @returns {string} formatted token argument
40
+ */
41
+ function formatInteger( token ) {
42
+ var base;
43
+ var out;
44
+ var i;
45
+
46
+ switch ( token.specifier ) {
47
+ case 'b':
48
+ // Case: %b (binary)
49
+ base = 2;
50
+ break;
51
+ case 'o':
52
+ // Case: %o (octal)
53
+ base = 8;
54
+ break;
55
+ case 'x':
56
+ case 'X':
57
+ // Case: %x, %X (hexadecimal)
58
+ base = 16;
59
+ break;
60
+ case 'd':
61
+ case 'i':
62
+ case 'u':
63
+ default:
64
+ // Case: %d, %i, %u (decimal)
65
+ base = 10;
66
+ break;
67
+ }
68
+ out = token.arg;
69
+ i = parseInt( out, 10 );
70
+ if ( !isFinite( i ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.
71
+ if ( !isNumber( out ) ) {
72
+ throw new Error( 'invalid integer. Value: ' + out );
73
+ }
74
+ i = 0;
75
+ }
76
+ if ( i < 0 && ( token.specifier === 'u' || base !== 10 ) ) {
77
+ i = 0xffffffff + i + 1;
78
+ }
79
+ if ( i < 0 ) {
80
+ out = ( -i ).toString( base );
81
+ if ( token.precision ) {
82
+ out = zeroPad( out, token.precision, token.padRight );
83
+ }
84
+ out = '-' + out;
85
+ } else {
86
+ out = i.toString( base );
87
+ if ( !i && !token.precision ) {
88
+ out = '';
89
+ } else if ( token.precision ) {
90
+ out = zeroPad( out, token.precision, token.padRight );
91
+ }
92
+ if ( token.sign ) {
93
+ out = token.sign + out;
94
+ }
95
+ }
96
+ if ( base === 16 ) {
97
+ if ( token.alternate ) {
98
+ out = '0x' + out;
99
+ }
100
+ out = ( token.specifier === uppercase.call( token.specifier ) ) ?
101
+ uppercase.call( out ) :
102
+ lowercase.call( out );
103
+ }
104
+ if ( base === 8 ) {
105
+ if ( token.alternate && out.charAt( 0 ) !== '0' ) {
106
+ out = '0' + out;
107
+ }
108
+ }
109
+ return out;
110
+ }
111
+
112
+
113
+ // EXPORTS //
114
+
115
+ module.exports = formatInteger;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2022 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ /**
22
+ * Generate string from a token array by interpolating values.
23
+ *
24
+ * @module @stdlib/string-base-format-interpolate
25
+ *
26
+ * @example
27
+ * var formatInterpolate = require( '@stdlib/string-base-format-interpolate' );
28
+ *
29
+ * var tokens = ['Hello ', { 'specifier': 's' }, '!' ];
30
+ * var out = formatInterpolate( tokens, 'World' );
31
+ * // returns 'Hello World!'
32
+ */
33
+
34
+ // MODULES //
35
+
36
+ var main = require( './main.js' );
37
+
38
+
39
+ // EXPORTS //
40
+
41
+ module.exports = main;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2022 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ /**
22
+ * Tests if a value is a number primitive.
23
+ *
24
+ * @param {*} value - value to test
25
+ * @returns {boolean} boolean indicating if a value is a number primitive
26
+ *
27
+ * @example
28
+ * var bool = isNumber( 3.14 );
29
+ * // returns true
30
+ *
31
+ * @example
32
+ * var bool = isNumber( NaN );
33
+ * // returns true
34
+ *
35
+ * @example
36
+ * var bool = isNumber( new Number( 3.14 ) );
37
+ * // returns false
38
+ */
39
+ function isNumber( value ) {
40
+ return ( typeof value === 'number' ); // NOTE: we inline the `isNumber.isPrimitive` function from `@stdlib/assert/is-number` in order to avoid circular dependencies.
41
+ }
42
+
43
+
44
+ // EXPORTS //
45
+
46
+ module.exports = isNumber;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2022 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ /**
22
+ * Tests if a value is a string primitive.
23
+ *
24
+ * @param {*} value - value to test
25
+ * @returns {boolean} boolean indicating if a value is a string primitive
26
+ *
27
+ * @example
28
+ * var bool = isString( 'beep' );
29
+ * // returns true
30
+ *
31
+ * @example
32
+ * var bool = isString( new String( 'beep' ) );
33
+ * // returns false
34
+ */
35
+ function isString( value ) {
36
+ return ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.
37
+ }
38
+
39
+
40
+ // EXPORTS //
41
+
42
+ module.exports = isString;
@@ -0,0 +1,243 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2022 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var formatInteger = require( './format_integer.js' );
24
+ var isString = require( './is_string.js' );
25
+ var isNumber = require( './is_number.js' );
26
+ var formatDouble = require( './format_double.js' );
27
+ var spacePad = require( './space_pad.js' );
28
+ var zeroPad = require( './zero_pad.js' );
29
+
30
+
31
+ // VARIABLES //
32
+
33
+ var fromCharCode = String.fromCharCode;
34
+ var isArray = Array.isArray; // NOTE: We use the global `Array.isArray` function here instead of `@stdlib/assert/is-array` to avoid circular dependencies.
35
+
36
+
37
+ // FUNCTIONS //
38
+
39
+ /**
40
+ * Returns a boolean indicating whether a value is `NaN`.
41
+ *
42
+ * @private
43
+ * @param {*} value - input value
44
+ * @returns {boolean} boolean indicating whether a value is `NaN`
45
+ *
46
+ * @example
47
+ * var bool = isnan( NaN );
48
+ * // returns true
49
+ *
50
+ * @example
51
+ * var bool = isnan( 4 );
52
+ * // returns false
53
+ */
54
+ function isnan( value ) { // explicitly define a function here instead of `@stdlib/math/base/assert/is-nan` in order to avoid circular dependencies
55
+ return ( value !== value );
56
+ }
57
+
58
+ /**
59
+ * Initializes token object with properties of supplied format identifier object or default values if not present.
60
+ *
61
+ * @private
62
+ * @param {Object} token - format identifier object
63
+ * @returns {Object} token object
64
+ */
65
+ function initialize( token ) {
66
+ var out = {};
67
+ out.specifier = token.specifier;
68
+ out.precision = ( token.precision === void 0 ) ? 1 : token.precision;
69
+ out.width = token.width;
70
+ out.flags = token.flags || '';
71
+ out.mapping = token.mapping;
72
+ return out;
73
+ }
74
+
75
+
76
+ // MAIN //
77
+
78
+ /**
79
+ * Generates string from a token array by interpolating values.
80
+ *
81
+ * @param {Array} tokens - string parts and format identifier objects
82
+ * @param {Array} ...args - variable values
83
+ * @throws {TypeError} first argument must be an array
84
+ * @throws {Error} invalid flags
85
+ * @returns {string} formatted string
86
+ *
87
+ * @example
88
+ * var tokens = [ 'beep ', { 'specifier': 's' } ];
89
+ * var out = formatInterpolate( tokens, 'boop' );
90
+ * // returns 'beep boop'
91
+ */
92
+ function formatInterpolate( tokens ) {
93
+ var hasPeriod;
94
+ var flags;
95
+ var token;
96
+ var flag;
97
+ var num;
98
+ var out;
99
+ var pos;
100
+ var f;
101
+ var i;
102
+ var j;
103
+
104
+ if ( !isArray( tokens ) ) {
105
+ throw new TypeError( 'invalid argument. First argument must be an array. Value: `' + tokens + '`.' );
106
+ }
107
+ out = '';
108
+ pos = 1;
109
+ for ( i = 0; i < tokens.length; i++ ) {
110
+ token = tokens[ i ];
111
+ if ( isString( token ) ) {
112
+ out += token;
113
+ } else {
114
+ hasPeriod = token.precision !== void 0;
115
+ token = initialize( token );
116
+ if ( !token.specifier ) {
117
+ throw new TypeError( 'invalid argument. Token is missing `specifier` property. Index: `'+ i +'`. Value: `' + token + '`.' );
118
+ }
119
+ if ( token.mapping ) {
120
+ pos = token.mapping;
121
+ }
122
+ flags = token.flags;
123
+ for ( j = 0; j < flags.length; j++ ) {
124
+ flag = flags.charAt( j );
125
+ switch ( flag ) {
126
+ case ' ':
127
+ token.sign = ' ';
128
+ break;
129
+ case '+':
130
+ token.sign = '+';
131
+ break;
132
+ case '-':
133
+ token.padRight = true;
134
+ token.padZeros = false;
135
+ break;
136
+ case '0':
137
+ token.padZeros = flags.indexOf( '-' ) < 0; // NOTE: We use built-in `Array.prototype.indexOf` here instead of `@stdlib/assert/contains` in order to avoid circular dependencies.
138
+ break;
139
+ case '#':
140
+ token.alternate = true;
141
+ break;
142
+ default:
143
+ throw new Error( 'invalid flag: ' + flag );
144
+ }
145
+ }
146
+ if ( token.width === '*' ) {
147
+ token.width = parseInt( arguments[ pos ], 10 );
148
+ pos += 1;
149
+ if ( isnan( token.width ) ) {
150
+ throw new TypeError( 'the argument for * width at position ' + pos + ' is not a number. Value: `' + token.width + '`.' );
151
+ }
152
+ if ( token.width < 0 ) {
153
+ token.padRight = true;
154
+ token.width = -token.width;
155
+ }
156
+ }
157
+ if ( hasPeriod ) {
158
+ if ( token.precision === '*' ) {
159
+ token.precision = parseInt( arguments[ pos ], 10 );
160
+ pos += 1;
161
+ if ( isnan( token.precision ) ) {
162
+ throw new TypeError( 'the argument for * precision at position ' + pos + ' is not a number. Value: `' + token.precision + '`.' );
163
+ }
164
+ if ( token.precision < 0 ) {
165
+ token.precision = 1;
166
+ hasPeriod = false;
167
+ }
168
+ }
169
+ }
170
+ token.arg = arguments[ pos ];
171
+ switch ( token.specifier ) {
172
+ case 'b':
173
+ case 'o':
174
+ case 'x':
175
+ case 'X':
176
+ case 'd':
177
+ case 'i':
178
+ case 'u':
179
+ // Case: %b (binary), %o (octal), %x, %X (hexadecimal), %d, %i (decimal), %u (unsigned decimal)
180
+ if ( hasPeriod ) {
181
+ token.padZeros = false;
182
+ }
183
+ token.arg = formatInteger( token );
184
+ break;
185
+ case 's':
186
+ // Case: %s (string)
187
+ token.maxWidth = ( hasPeriod ) ? token.precision : -1;
188
+ token.arg = String( token.arg );
189
+ break;
190
+ case 'c':
191
+ // Case: %c (character)
192
+ if ( !isnan( token.arg ) ) {
193
+ num = parseInt( token.arg, 10 );
194
+ if ( num < 0 || num > 127 ) {
195
+ throw new Error( 'invalid character code. Value: ' + token.arg );
196
+ }
197
+ token.arg = ( isnan( num ) ) ? String( token.arg ) : fromCharCode( num ); // eslint-disable-line max-len
198
+ }
199
+ break;
200
+ case 'e':
201
+ case 'E':
202
+ case 'f':
203
+ case 'F':
204
+ case 'g':
205
+ case 'G':
206
+ // Case: %e, %E (scientific notation), %f, %F (decimal floating point), %g, %G (uses the shorter of %e/E or %f/F)
207
+ if ( !hasPeriod ) {
208
+ token.precision = 6;
209
+ }
210
+ f = parseFloat( token.arg );
211
+ if ( !isFinite( f ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.
212
+ if ( !isNumber( token.arg ) ) {
213
+ throw new Error( 'invalid floating-point number. Value: ' + out );
214
+ }
215
+ // Case: NaN, Infinity, or -Infinity
216
+ f = token.arg;
217
+ token.padZeros = false;
218
+ }
219
+ token.arg = formatDouble( f, token );
220
+ break;
221
+ default:
222
+ throw new Error( 'invalid specifier: ' + token.specifier );
223
+ }
224
+ // Fit argument into field width...
225
+ if ( token.maxWidth >= 0 && token.arg.length > token.maxWidth ) {
226
+ token.arg = token.arg.substring( 0, token.maxWidth );
227
+ }
228
+ if ( token.padZeros ) {
229
+ token.arg = zeroPad( token.arg, token.width || token.precision, token.padRight ); // eslint-disable-line max-len
230
+ } else if ( token.width ) {
231
+ token.arg = spacePad( token.arg, token.width, token.padRight );
232
+ }
233
+ out += token.arg || '';
234
+ pos += 1;
235
+ }
236
+ }
237
+ return out;
238
+ }
239
+
240
+
241
+ // EXPORTS //
242
+
243
+ module.exports = formatInterpolate;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2022 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // FUNCTIONS //
22
+
23
+ /**
24
+ * Returns `n` spaces.
25
+ *
26
+ * @private
27
+ * @param {number} n - number of spaces
28
+ * @returns {string} string of spaces
29
+ */
30
+ function spaces( n ) {
31
+ var out = '';
32
+ var i;
33
+ for ( i = 0; i < n; i++ ) {
34
+ out += ' ';
35
+ }
36
+ return out;
37
+ }
38
+
39
+
40
+ // MAIN //
41
+
42
+ /**
43
+ * Pads a token with spaces to the specified width.
44
+ *
45
+ * @private
46
+ * @param {string} str - token argument
47
+ * @param {number} width - token width
48
+ * @param {boolean} [right=false] - boolean indicating whether to pad to the right
49
+ * @returns {string} padded token argument
50
+ */
51
+ function spacePad( str, width, right ) {
52
+ var pad = width - str.length;
53
+ if ( pad < 0 ) {
54
+ return str;
55
+ }
56
+ str = ( right ) ?
57
+ str + spaces( pad ) :
58
+ spaces( pad ) + str;
59
+ return str;
60
+ }
61
+
62
+
63
+ // EXPORTS //
64
+
65
+ module.exports = spacePad;