@stdlib/string-for-each 0.0.1 → 0.2.0
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.
- package/NOTICE +1 -1
- package/README.md +30 -4
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +1 -1
- package/package.json +15 -13
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2024 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -18,6 +18,17 @@ limitations under the License.
|
|
|
18
18
|
|
|
19
19
|
-->
|
|
20
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
|
+
|
|
21
32
|
# forEach
|
|
22
33
|
|
|
23
34
|
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
|
|
@@ -103,7 +114,7 @@ The function supports the following options:
|
|
|
103
114
|
- `'grapheme'`: grapheme clusters. Appropriate for strings containing visual characters which can span multiple Unicode code points (e.g., emoji).
|
|
104
115
|
- `'code_point'`: Unicode code points. Appropriate for strings containing visual characters which are comprised of more than one Unicode code unit (e.g., ideographic symbols and punctuation and mathematical alphanumerics).
|
|
105
116
|
- `'code_unit'`: UTF-16 code units. Appropriate for strings containing visual characters drawn from the basic multilingual plane (BMP) (e.g., common characters, such as those from the Latin, Greek, and Cyrillic alphabets).
|
|
106
|
-
|
|
117
|
+
|
|
107
118
|
Default: `'grapheme'`.
|
|
108
119
|
|
|
109
120
|
</section>
|
|
@@ -159,6 +170,12 @@ forEach( '\uD834\uDD1E', log );
|
|
|
159
170
|
|
|
160
171
|
<section class="related">
|
|
161
172
|
|
|
173
|
+
* * *
|
|
174
|
+
|
|
175
|
+
## See Also
|
|
176
|
+
|
|
177
|
+
- <span class="package-name">[`@stdlib/utils-for-each`][@stdlib/utils/for-each]</span><span class="delimiter">: </span><span class="description">invoke a function for each element in a collection.</span>
|
|
178
|
+
|
|
162
179
|
</section>
|
|
163
180
|
|
|
164
181
|
<!-- /.related -->
|
|
@@ -189,7 +206,7 @@ See [LICENSE][stdlib-license].
|
|
|
189
206
|
|
|
190
207
|
## Copyright
|
|
191
208
|
|
|
192
|
-
Copyright © 2016-
|
|
209
|
+
Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
193
210
|
|
|
194
211
|
</section>
|
|
195
212
|
|
|
@@ -202,8 +219,8 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors].
|
|
|
202
219
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/string-for-each.svg
|
|
203
220
|
[npm-url]: https://npmjs.org/package/@stdlib/string-for-each
|
|
204
221
|
|
|
205
|
-
[test-image]: https://github.com/stdlib-js/string-for-each/actions/workflows/test.yml/badge.svg?branch=v0.0
|
|
206
|
-
[test-url]: https://github.com/stdlib-js/string-for-each/actions/workflows/test.yml?query=branch:v0.0
|
|
222
|
+
[test-image]: https://github.com/stdlib-js/string-for-each/actions/workflows/test.yml/badge.svg?branch=v0.2.0
|
|
223
|
+
[test-url]: https://github.com/stdlib-js/string-for-each/actions/workflows/test.yml?query=branch:v0.2.0
|
|
207
224
|
|
|
208
225
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/string-for-each/main.svg
|
|
209
226
|
[coverage-url]: https://codecov.io/github/stdlib-js/string-for-each?branch=main
|
|
@@ -226,12 +243,21 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors].
|
|
|
226
243
|
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
227
244
|
|
|
228
245
|
[deno-url]: https://github.com/stdlib-js/string-for-each/tree/deno
|
|
246
|
+
[deno-readme]: https://github.com/stdlib-js/string-for-each/blob/deno/README.md
|
|
229
247
|
[umd-url]: https://github.com/stdlib-js/string-for-each/tree/umd
|
|
248
|
+
[umd-readme]: https://github.com/stdlib-js/string-for-each/blob/umd/README.md
|
|
230
249
|
[esm-url]: https://github.com/stdlib-js/string-for-each/tree/esm
|
|
250
|
+
[esm-readme]: https://github.com/stdlib-js/string-for-each/blob/esm/README.md
|
|
231
251
|
[branches-url]: https://github.com/stdlib-js/string-for-each/blob/main/branches.md
|
|
232
252
|
|
|
233
253
|
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/string-for-each/main/LICENSE
|
|
234
254
|
|
|
255
|
+
<!-- <related-links> -->
|
|
256
|
+
|
|
257
|
+
[@stdlib/utils/for-each]: https://www.npmjs.com/package/@stdlib/utils-for-each
|
|
258
|
+
|
|
259
|
+
<!-- </related-links> -->
|
|
260
|
+
|
|
235
261
|
</section>
|
|
236
262
|
|
|
237
263
|
<!-- /.links -->
|
package/SECURITY.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";var d=function(a,e){return function(){return e||a((e={exports:{}}).exports,e),e.exports}};var l=d(function(P,v){
|
|
2
|
+
var f=require('@stdlib/assert-is-function/dist'),c=require('@stdlib/assert-is-string/dist').isPrimitive,m=require('@stdlib/assert-is-plain-object/dist'),g=require('@stdlib/assert-has-own-property/dist'),h=require('@stdlib/array-base-assert-contains/dist').factory,q=require('@stdlib/string-base-for-each/dist'),w=require('@stdlib/string-base-for-each-code-point/dist'),E=require('@stdlib/string-base-for-each-grapheme-cluster/dist'),n=require('@stdlib/error-tools-fmtprodmsg/dist'),s=["grapheme","code_point","code_unit"],p={grapheme:E,code_point:w,code_unit:q},b=h(s);function y(a,e,t){var u,o,i,r;if(!c(a))throw new TypeError(n('1gr3F',a));if(i={mode:"grapheme"},o=arguments.length,o===2)r=e,e=null;else if(o===3)m(e)?r=t:(r=e,e=null,u=t);else{if(!m(e))throw new TypeError(n('1gr2V',e));r=t,u=arguments[3]}if(!f(r))throw new TypeError(n('1gr2b',r));if(e&&g(e,"mode")&&(i.mode=e.mode,!b(i.mode)))throw new TypeError(n('1grE1',"mode",s.join('", "'),i.mode));return p[i.mode](a,r,u),a}v.exports=y
|
|
3
|
+
});var C=l();module.exports=C;
|
|
4
|
+
/** @license Apache-2.0 */
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../lib/main.js", "../lib/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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 isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isPlainObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar contains = require( '@stdlib/array-base-assert-contains' ).factory;\nvar forEachCodeUnit = require( '@stdlib/string-base-for-each' );\nvar forEachCodePoint = require( '@stdlib/string-base-for-each-code-point' );\nvar forEachGraphemeCluster = require( '@stdlib/string-base-for-each-grapheme-cluster' );\nvar format = require( '@stdlib/string-format' );\n\n\n// VARIABLES //\n\nvar MODES = [ 'grapheme', 'code_point', 'code_unit' ];\nvar FCNS = {\n\t'grapheme': forEachGraphemeCluster,\n\t'code_point': forEachCodePoint,\n\t'code_unit': forEachCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Invokes a function for each character in a string.\n*\n* @param {string} str - input string\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" over which to iterate (must be either `grapheme`, `code_point`, or `code_unit`)\n* @param {Function} clbk - function to invoke\n* @param {*} [thisArg] - execution context\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} callback argument must be a function\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} input string\n*\n* @example\n* function log( value, index ) {\n* console.log( '%d: %s', index, value );\n* }\n*\n* forEach( 'Hello', log );\n*/\nfunction forEach( str, options, clbk ) {\n\tvar thisArg;\n\tvar nargs;\n\tvar opts;\n\tvar cb;\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 2 ) {\n\t\tcb = options;\n\t\toptions = null;\n\t} else if ( nargs === 3 ) {\n\t\tif ( isPlainObject( options ) ) {\n\t\t\tcb = clbk;\n\t\t} else {\n\t\t\tcb = options;\n\t\t\toptions = null;\n\t\t\tthisArg = clbk;\n\t\t}\n\t} else { // nargs === 4\n\t\tif ( !isPlainObject( options ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t\t}\n\t\tcb = clbk;\n\t\tthisArg = arguments[ 3 ];\n\t}\n\tif ( !isFunction( cb ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', cb ) );\n\t}\n\tif ( options ) {\n\t\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\t\topts.mode = options.mode;\n\t\t\tif ( !isMode( opts.mode ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be one of the following: \"%s\". Value: `%s`.', 'mode', MODES.join( '\", \"' ), opts.mode ) );\n\t\t\t}\n\t\t}\n\t}\n\tFCNS[ opts.mode ]( str, cb, thisArg );\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = forEach;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 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* Invoke a function for each character in a string.\n*\n* @module @stdlib/string-for-each\n*\n* @example\n* var forEach = require( '@stdlib/string-for-each' );\n*\n* function log( value, index ) {\n* console.log( '%d: %s', index, value );\n* }\n*\n* forEach( 'Hello', log );\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,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,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"names": ["require_main", "__commonJSMin", "exports", "module", "isFunction", "isString", "isPlainObject", "hasOwnProp", "contains", "forEachCodeUnit", "forEachCodePoint", "forEachGraphemeCluster", "format", "MODES", "FCNS", "isMode", "forEach", "str", "options", "clbk", "thisArg", "nargs", "opts", "cb", "main"]
|
|
7
|
+
}
|
package/docs/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/string-for-each",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Invoke a function for each character in a string.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -37,22 +37,24 @@
|
|
|
37
37
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@stdlib/array-base-assert-contains": "^0.0
|
|
41
|
-
"@stdlib/assert-has-own-property": "^0.0
|
|
42
|
-
"@stdlib/assert-is-function": "^0.0
|
|
43
|
-
"@stdlib/assert-is-plain-object": "^0.0
|
|
44
|
-
"@stdlib/assert-is-string": "^0.0
|
|
45
|
-
"@stdlib/string-base-for-each": "^0.0
|
|
46
|
-
"@stdlib/string-base-for-each-code-point": "^0.0
|
|
47
|
-
"@stdlib/string-base-for-each-grapheme-cluster": "^0.0
|
|
48
|
-
"@stdlib/string-format": "^0.0
|
|
40
|
+
"@stdlib/array-base-assert-contains": "^0.2.0",
|
|
41
|
+
"@stdlib/assert-has-own-property": "^0.2.0",
|
|
42
|
+
"@stdlib/assert-is-function": "^0.2.0",
|
|
43
|
+
"@stdlib/assert-is-plain-object": "^0.2.0",
|
|
44
|
+
"@stdlib/assert-is-string": "^0.2.0",
|
|
45
|
+
"@stdlib/string-base-for-each": "^0.2.0",
|
|
46
|
+
"@stdlib/string-base-for-each-code-point": "^0.2.0",
|
|
47
|
+
"@stdlib/string-base-for-each-grapheme-cluster": "^0.2.0",
|
|
48
|
+
"@stdlib/string-format": "^0.2.0",
|
|
49
|
+
"@stdlib/error-tools-fmtprodmsg": "^0.2.0"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
|
-
"@stdlib/
|
|
52
|
-
"@stdlib/utils-noop": "^0.0.14",
|
|
52
|
+
"@stdlib/utils-noop": "^0.2.0",
|
|
53
53
|
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
54
54
|
"istanbul": "^0.4.1",
|
|
55
|
-
"tap-min": "git+https://github.com/Planeshifter/tap-min.git"
|
|
55
|
+
"tap-min": "git+https://github.com/Planeshifter/tap-min.git",
|
|
56
|
+
"@stdlib/bench-harness": "^0.2.0",
|
|
57
|
+
"@stdlib/bench": "^0.3.1"
|
|
56
58
|
},
|
|
57
59
|
"engines": {
|
|
58
60
|
"node": ">=0.10.0",
|