@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,341 @@
1
+ <!--
2
+
3
+ @license Apache-2.0
4
+
5
+ Copyright (c) 2022 The Stdlib Authors.
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ -->
20
+
21
+
22
+ <details>
23
+ <summary>
24
+ About stdlib...
25
+ </summary>
26
+ <p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
27
+ <p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
28
+ <p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
29
+ <p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
30
+ </details>
31
+
32
+ # format
33
+
34
+ [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
35
+
36
+ > Insert supplied variable values into a format string.
37
+
38
+ <section class="intro">
39
+
40
+ </section>
41
+
42
+ <!-- /.intro -->
43
+
44
+ <section class="installation">
45
+
46
+ ## Installation
47
+
48
+ ```bash
49
+ npm install @stdlib/string-format
50
+ ```
51
+
52
+ </section>
53
+
54
+ <section class="usage">
55
+
56
+ ## Usage
57
+
58
+ ```javascript
59
+ var format = require( '@stdlib/string-format' );
60
+ ```
61
+
62
+ #### format( str, ...args )
63
+
64
+ Inserts supplied variable values into a format string.
65
+
66
+ ```javascript
67
+ var str = 'Hello, %s! My name is %s.';
68
+ var out = format( str, 'world', 'Bob' );
69
+ // returns 'Hello, world! My name is Bob.'
70
+ ```
71
+
72
+ The format string is a string literal containing zero or more conversion specifications, each of which results in a string value being inserted to the output string. A conversion specification consists of a percent sign (`%`) followed by one or more of the following flags, width, precision, and conversion type characters. It thus takes the following form:
73
+
74
+ ```text
75
+ %[flags][width][.precision]specifier
76
+ ```
77
+
78
+ Arguments following the format string are used to replace the placeholders in the format string. The number of arguments following the format string should be equal to the number of placeholders in the format string.
79
+
80
+ ```javascript
81
+ var str = '%s %s';
82
+ var out = format( str, 'Hello', 'World' );
83
+ // returns 'Hello World'
84
+ ```
85
+
86
+ To supply arguments in a different order than they appear in the format string, positional placeholders as indicated by a `$` character in the format string are used. In this case, the conversion specification takes the form:
87
+
88
+ ```text
89
+ %[pos$][flags][width][.precision]specifier
90
+ ```
91
+
92
+ ```javascript
93
+ var str = '%3$s %2$s %1$s';
94
+ var out = format( str, 'foo', 'bar', 'baz' );
95
+ // returns 'baz bar foo'
96
+ ```
97
+
98
+ The following table summarizes the supported specifiers:
99
+
100
+ | type | description | example |
101
+ | ---- | --------------------------------- | --------- |
102
+ | s | string | beep boop |
103
+ | c | character | a |
104
+ | d, i | signed decimal integer | -12 |
105
+ | u | unsigned decimal integer | 390 |
106
+ | b | unsigned binary integer | 11011011 |
107
+ | o | unsigned octal integer | 510 |
108
+ | x | unsigned hexadecimal (lowercase) | 7b |
109
+ | X | unsigned hexadecimal (uppercase) | 7B |
110
+ | f, F | decimal floating point | 390.24 |
111
+ | e | scientific notation (lowercase) | 3.9e+1 |
112
+ | E | scientific notation (uppercase) | 3.9E+1 |
113
+ | g | shortest representation (`e`/`f`) | 3.9 |
114
+ | G | shortest representation (`E`/`F`) | 3.9 |
115
+
116
+ ```javascript
117
+ var str = '%i written as a binary number is %b.';
118
+ var out = format( str, 9, 9 );
119
+ // returns '9 written as a binary number is 1001.'
120
+
121
+ str = '%i written as an octal number is %o.';
122
+ out = format( str, 17, 17 );
123
+ // returns '17 written as an octal number is 21.'
124
+
125
+ str = '%i written as a hexadecimal number is %x.';
126
+ out = format( str, 255, 255 );
127
+ // returns '255 written as a hexadecimal number is ff.'
128
+
129
+ str = '%i written as a hexadecimal number is %X (uppercase letters).';
130
+ out = format( str, 255, 255 );
131
+ // returns '255 written as a hexadecimal number is FF (uppercase letters).'
132
+
133
+ str = '%i written as a floating point number with default precision is %f!';
134
+ out = format( str, 8, 8 );
135
+ // returns '8 written as a floating point number with default precision is 8.000000!'
136
+
137
+ str = 'Scientific notation: %e';
138
+ out = format( str, 3.14159 );
139
+ // returns 'Scientific notation: 3.141590e+00'
140
+
141
+ str = 'Scientific notation: %E (uppercase).';
142
+ out = format( str, 3.14159 );
143
+ // returns 'Scientific notation: 3.141590E+00 (uppercase).'
144
+
145
+ str = '%g (shortest representation)';
146
+ out = format( str, 3.14159 );
147
+ // returns '3.14159'
148
+ ```
149
+
150
+ A conversion specification may contain zero or more flags, which modify the behavior of the conversion. The following flags are supported:
151
+
152
+ | flag | description |
153
+ | ----- | ------------------------------------------------------------------------------------------ |
154
+ | - | left-justify the output within the given field width by padding with spaces on the right |
155
+ | 0 | left-pad the output with zeros instead of spaces when padding is required |
156
+ | # | use an alternative format for `o` and `x` conversions |
157
+ | + | prefix the output with a plus (+) or minus (-) sign even if the value is a positive number |
158
+ | space | prefix the value with a space character if no sign is written |
159
+
160
+ ```javascript
161
+ var str = 'Always prefix with a sign: %+i';
162
+ var out = format( str, 9 );
163
+ // returns 'Always prefix with a sign: +9'
164
+
165
+ out = format( str, -9 );
166
+ // returns 'Always prefix with a sign: -9'
167
+
168
+ str = 'Only prefix with a sign if negative: %i';
169
+ out = format( str, 6 );
170
+ // returns 'Only prefix with a sign if negative: 6'
171
+
172
+ out = format( str, -6 );
173
+ // returns 'Only prefix with a sign if negative: -6'
174
+
175
+ str = 'Prefix with a sign if negative and a space if positive: % i';
176
+ out = format( str, 3 );
177
+ // returns 'Prefix with a sign if negative and a space if positive: 3'
178
+
179
+ out = format( str, -3 );
180
+ // returns 'Prefix with a sign if negative and a space if positive: -3'
181
+ ```
182
+
183
+ The `width` may be specified as a decimal integer representing the minimum number of characters to be written to the output. If the value to be written is shorter than this number, the result is padded with spaces on the left. The value is not truncated even if the result is larger. Alternatively, the `width` may be specified as an asterisk character (`*`), in which case the argument preceding the conversion specification is used as the minimum field width.
184
+
185
+ ```javascript
186
+ var str = '%5s';
187
+ var out = format( str, 'baz' );
188
+ // returns ' baz'
189
+
190
+ str = '%-5s';
191
+ out = format( str, 'baz' );
192
+ // returns 'baz '
193
+
194
+ str = '%05i';
195
+ out = format( str, 2 );
196
+ // returns '00002'
197
+
198
+ str = '%*i';
199
+ out = format( str, 5, 2 );
200
+ // returns ' 2'
201
+ ```
202
+
203
+ The `precision` may be specified as a decimal integer or as an asterisk character (`*`), in which case the argument preceding the conversion specification is used as the precision value. The behavior of the `precision` differs depending on the conversion type:
204
+
205
+ - For `s` specifiers, the `precision` specifies the maximum number of characters to be written to the output.
206
+ - For floating point specifiers (`f`, `F`, `e`, `E`), the `precision` specifies the number of digits after the decimal point to be written to the output (by default, this is `6`).
207
+ - For `g` and `G` specifiers, the `precision` specifies the maximum number of significant digits to be written to the output.
208
+ - For integer specifiers (`d`, `i`, `u`, `b`, `o`, `x`, `X`), the `precision` specifies the minimum number of digits to be written to the output. If the value to be written is shorter than this number, the result is padded with zeros on the left. The value is not truncated even if the result is longer.
209
+
210
+ Alternatively, the `precision` may be specified as an asterisk character (`*`), in which case the argument preceding the conversion specification is used as the minimum number of digits.
211
+
212
+ ```javascript
213
+ var str = '%5.2s';
214
+ var out = format( str, 'baz' );
215
+ // returns ' ba'
216
+
217
+ str = 'PI: ~%.2f';
218
+ out = format( str, 3.14159 );
219
+ // returns 'PI: ~3.14'
220
+
221
+ str = 'Agent %.3i';
222
+ out = format( str, 7 );
223
+ // returns 'Agent 007'
224
+ ```
225
+
226
+ </section>
227
+
228
+ <!-- /.usage -->
229
+
230
+ <section class="examples">
231
+
232
+ ## Examples
233
+
234
+ <!-- eslint no-undef: "error" -->
235
+
236
+ ```javascript
237
+ var format = require( '@stdlib/string-format' );
238
+
239
+ var out = format( '%s %s!', 'Hello', 'World' );
240
+ // returns 'Hello World!'
241
+
242
+ out = format( 'Pi: ~%.2f', 3.141592653589793 );
243
+ // returns 'Pi: ~3.14'
244
+
245
+ out = format( '%-10s %-10s', 'a', 'b' );
246
+ // returns 'a b '
247
+
248
+ out = format( '%10s %10s', 'a', 'b' );
249
+ // returns ' a b'
250
+
251
+ out = format( '%2$s %1$s %3$s', 'b', 'a', 'c' );
252
+ // returns 'a b c'
253
+ ```
254
+
255
+ </section>
256
+
257
+ <!-- /.examples -->
258
+
259
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
260
+
261
+ <section class="related">
262
+
263
+ </section>
264
+
265
+ <!-- /.related -->
266
+
267
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
268
+
269
+
270
+ <section class="main-repo" >
271
+
272
+ * * *
273
+
274
+ ## Notice
275
+
276
+ This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
277
+
278
+ For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
279
+
280
+ #### Community
281
+
282
+ [![Chat][chat-image]][chat-url]
283
+
284
+ ---
285
+
286
+ ## License
287
+
288
+ See [LICENSE][stdlib-license].
289
+
290
+
291
+ ## Copyright
292
+
293
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
294
+
295
+ </section>
296
+
297
+ <!-- /.stdlib -->
298
+
299
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
300
+
301
+ <section class="links">
302
+
303
+ [npm-image]: http://img.shields.io/npm/v/@stdlib/string-format.svg
304
+ [npm-url]: https://npmjs.org/package/@stdlib/string-format
305
+
306
+ [test-image]: https://github.com/stdlib-js/string-format/actions/workflows/test.yml/badge.svg?branch=v0.2.3
307
+ [test-url]: https://github.com/stdlib-js/string-format/actions/workflows/test.yml?query=branch:v0.2.3
308
+
309
+ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/string-format/main.svg
310
+ [coverage-url]: https://codecov.io/github/stdlib-js/string-format?branch=main
311
+
312
+ <!--
313
+
314
+ [dependencies-image]: https://img.shields.io/david/stdlib-js/string-format.svg
315
+ [dependencies-url]: https://david-dm.org/stdlib-js/string-format/main
316
+
317
+ -->
318
+
319
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
320
+ [chat-url]: https://stdlib.zulipchat.com
321
+
322
+ [stdlib]: https://github.com/stdlib-js/stdlib
323
+
324
+ [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
325
+
326
+ [umd]: https://github.com/umdjs/umd
327
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
328
+
329
+ [deno-url]: https://github.com/stdlib-js/string-format/tree/deno
330
+ [deno-readme]: https://github.com/stdlib-js/string-format/blob/deno/README.md
331
+ [umd-url]: https://github.com/stdlib-js/string-format/tree/umd
332
+ [umd-readme]: https://github.com/stdlib-js/string-format/blob/umd/README.md
333
+ [esm-url]: https://github.com/stdlib-js/string-format/tree/esm
334
+ [esm-readme]: https://github.com/stdlib-js/string-format/blob/esm/README.md
335
+ [branches-url]: https://github.com/stdlib-js/string-format/blob/main/branches.md
336
+
337
+ [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/string-format/main/LICENSE
338
+
339
+ </section>
340
+
341
+ <!-- /.links -->
@@ -0,0 +1,5 @@
1
+ # Security
2
+
3
+ > Policy for reporting security vulnerabilities.
4
+
5
+ See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security).
@@ -0,0 +1,3 @@
1
+ /// <reference path="../docs/types/index.d.ts" />
2
+ import format from '../docs/types/index';
3
+ export = format;
@@ -0,0 +1,7 @@
1
+ "use strict";var i=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var u=i(function(c,n){
2
+ function g(e){return typeof e=="string"}n.exports=g
3
+ });var o=i(function(q,s){
4
+ var p=require('@stdlib/string-base-format-interpolate/dist'),l=require('@stdlib/string-base-format-tokenize/dist'),m=u();function a(e){var r,t;if(!m(e))throw new TypeError(a('1Of3F',e));for(r=[l(e)],t=1;t<arguments.length;t++)r.push(arguments[t]);return p.apply(null,r)}s.exports=a
5
+ });var v=o();module.exports=v;
6
+ /** @license Apache-2.0 */
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../lib/is_string.js", "../lib/main.js", "../lib/index.js"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar interpolate = require( '@stdlib/string-base-format-interpolate' );\nvar tokenize = require( '@stdlib/string-base-format-tokenize' );\nvar isString = require( './is_string.js' );\n\n\n// MAIN //\n\n/**\n* Inserts supplied variable values into a format string.\n*\n* @param {string} str - input string\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be a string\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var str = format( 'Hello %s!', 'world' );\n* // returns 'Hello world!'\n*\n* @example\n* var str = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\nfunction format( str ) {\n\tvar args;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\targs = [ tokenize( str ) ];\n\tfor ( i = 1; i < arguments.length; i++ ) {\n\t\targs.push( arguments[ i ] );\n\t}\n\treturn interpolate.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = format;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Insert supplied variable values into a format string.\n*\n* @module @stdlib/string-format\n*\n* @example\n* var format = require( '@stdlib/string-format' );\n*\n* var out = format( '%s %s!', 'Hello', 'World' );\n* // returns 'Hello World!'\n*\n* out = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAkCA,SAASC,EAAUC,EAAQ,CAC1B,OAAS,OAAOA,GAAU,QAC3B,CAKAF,EAAO,QAAUC,ICzCjB,IAAAE,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,wCAAyC,EAChEC,EAAW,QAAS,qCAAsC,EAC1DC,EAAW,IAsBf,SAASC,EAAQC,EAAM,CACtB,IAAIC,EACAC,EAEJ,GAAK,CAACJ,EAAUE,CAAI,EACnB,MAAM,IAAI,UAAWD,EAAQ,kEAAmEC,CAAI,CAAE,EAGvG,IADAC,EAAO,CAAEJ,EAAUG,CAAI,CAAE,EACnBE,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAClCD,EAAK,KAAM,UAAWC,CAAE,CAAE,EAE3B,OAAON,EAAY,MAAO,KAAMK,CAAK,CACtC,CAKAN,EAAO,QAAUI,IC1BjB,IAAII,EAAO,IAKX,OAAO,QAAUA",
6
+ "names": ["require_is_string", "__commonJSMin", "exports", "module", "isString", "value", "require_main", "__commonJSMin", "exports", "module", "interpolate", "tokenize", "isString", "format", "str", "args", "i", "main"]
7
+ }
@@ -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
+ // TypeScript Version: 4.1
20
+
21
+ /**
22
+ * Inserts supplied variable values into a format string.
23
+ *
24
+ * @param str - input string
25
+ * @param args - variable values
26
+ * @throws invalid flags
27
+ * @returns formatted string
28
+ *
29
+ * @example
30
+ * var str = format( 'Hello %s!', 'world' );
31
+ * // returns 'Hello world!'
32
+ *
33
+ * @example
34
+ * var str = format( 'Pi: ~%.2f', 3.141592653589793 );
35
+ * // returns 'Pi: ~3.14'
36
+ */
37
+ declare function format( str: string, ...args: Array<any> ): string;
38
+
39
+
40
+ // EXPORTS //
41
+
42
+ export = format;
@@ -0,0 +1,43 @@
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
+ * Insert supplied variable values into a format string.
23
+ *
24
+ * @module @stdlib/string-format
25
+ *
26
+ * @example
27
+ * var format = require( '@stdlib/string-format' );
28
+ *
29
+ * var out = format( '%s %s!', 'Hello', 'World' );
30
+ * // returns 'Hello World!'
31
+ *
32
+ * out = format( 'Pi: ~%.2f', 3.141592653589793 );
33
+ * // returns 'Pi: ~3.14'
34
+ */
35
+
36
+ // MODULES //
37
+
38
+ var main = require( './main.js' );
39
+
40
+
41
+ // EXPORTS //
42
+
43
+ module.exports = main;
@@ -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,64 @@
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 interpolate = require( '@stdlib/string-base-format-interpolate' );
24
+ var tokenize = require( '@stdlib/string-base-format-tokenize' );
25
+ var isString = require( './is_string.js' );
26
+
27
+
28
+ // MAIN //
29
+
30
+ /**
31
+ * Inserts supplied variable values into a format string.
32
+ *
33
+ * @param {string} str - input string
34
+ * @param {Array} ...args - variable values
35
+ * @throws {TypeError} first argument must be a string
36
+ * @throws {Error} invalid flags
37
+ * @returns {string} formatted string
38
+ *
39
+ * @example
40
+ * var str = format( 'Hello %s!', 'world' );
41
+ * // returns 'Hello world!'
42
+ *
43
+ * @example
44
+ * var str = format( 'Pi: ~%.2f', 3.141592653589793 );
45
+ * // returns 'Pi: ~3.14'
46
+ */
47
+ function format( str ) {
48
+ var args;
49
+ var i;
50
+
51
+ if ( !isString( str ) ) {
52
+ throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );
53
+ }
54
+ args = [ tokenize( str ) ];
55
+ for ( i = 1; i < arguments.length; i++ ) {
56
+ args.push( arguments[ i ] );
57
+ }
58
+ return interpolate.apply( null, args );
59
+ }
60
+
61
+
62
+ // EXPORTS //
63
+
64
+ module.exports = format;
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@stdlib/string-format",
3
+ "version": "0.2.3",
4
+ "description": "Insert supplied variable values into a format string.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "The Stdlib Authors",
8
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "The Stdlib Authors",
13
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
+ }
15
+ ],
16
+ "main": "./lib",
17
+ "directories": {
18
+ "doc": "./docs",
19
+ "lib": "./lib",
20
+ "dist": "./dist"
21
+ },
22
+ "types": "./docs/types",
23
+ "scripts": {},
24
+ "homepage": "https://stdlib.io",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git://github.com/stdlib-js/string-format.git"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/stdlib-js/stdlib/issues"
31
+ },
32
+ "dependencies": {
33
+ "@stdlib/string-base-format-interpolate": "^0.2.3",
34
+ "@stdlib/string-base-format-tokenize": "^0.2.4"
35
+ },
36
+ "devDependencies": {},
37
+ "engines": {
38
+ "node": ">=0.10.0",
39
+ "npm": ">2.7.0"
40
+ },
41
+ "os": [
42
+ "aix",
43
+ "darwin",
44
+ "freebsd",
45
+ "linux",
46
+ "macos",
47
+ "openbsd",
48
+ "sunos",
49
+ "win32",
50
+ "windows"
51
+ ],
52
+ "keywords": [
53
+ "stdlib",
54
+ "stdstring",
55
+ "utilities",
56
+ "utility",
57
+ "utils",
58
+ "util",
59
+ "string",
60
+ "str",
61
+ "format",
62
+ "fmt",
63
+ "formatter",
64
+ "sprintf",
65
+ "printf",
66
+ "print"
67
+ ],
68
+ "funding": {
69
+ "type": "opencollective",
70
+ "url": "https://opencollective.com/stdlib"
71
+ }
72
+ }