@stdlib/string-first 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 +25 -6
- 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 +2 -2
- package/package.json +10 -10
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
|
# first
|
|
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] -->
|
|
@@ -61,7 +72,7 @@ The function supports the following options:
|
|
|
61
72
|
- `'grapheme'`: grapheme clusters. Appropriate for strings containing visual characters which can span multiple Unicode code points (e.g., emoji).
|
|
62
73
|
- `'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).
|
|
63
74
|
- `'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).
|
|
64
|
-
|
|
75
|
+
|
|
65
76
|
Default: `'grapheme'`.
|
|
66
77
|
|
|
67
78
|
By default, the function returns the first character. To return the first `n` characters, provide a second argument specifying the number of characters to return.
|
|
@@ -90,7 +101,6 @@ out = first( 'foo bar', 10 );
|
|
|
90
101
|
|
|
91
102
|
<!-- /.notes -->
|
|
92
103
|
|
|
93
|
-
|
|
94
104
|
<section class="examples">
|
|
95
105
|
|
|
96
106
|
## Examples
|
|
@@ -135,7 +145,7 @@ str = first( '🐶🐮🐷🐰🐸', 10 );
|
|
|
135
145
|
## See Also
|
|
136
146
|
|
|
137
147
|
- <span class="package-name">[`@stdlib/string-first-cli`][@stdlib/string-first-cli]</span><span class="delimiter">: </span><span class="description">CLI package for use as a command-line utility.</span>
|
|
138
|
-
|
|
148
|
+
- <span class="package-name">[`@stdlib/string-remove-first`][@stdlib/string/remove-first]</span><span class="delimiter">: </span><span class="description">remove the first character(s) of a string.</span>
|
|
139
149
|
|
|
140
150
|
</section>
|
|
141
151
|
|
|
@@ -167,7 +177,7 @@ See [LICENSE][stdlib-license].
|
|
|
167
177
|
|
|
168
178
|
## Copyright
|
|
169
179
|
|
|
170
|
-
Copyright © 2016-
|
|
180
|
+
Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
171
181
|
|
|
172
182
|
</section>
|
|
173
183
|
|
|
@@ -182,8 +192,8 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors].
|
|
|
182
192
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/string-first.svg
|
|
183
193
|
[npm-url]: https://npmjs.org/package/@stdlib/string-first
|
|
184
194
|
|
|
185
|
-
[test-image]: https://github.com/stdlib-js/string-first/actions/workflows/test.yml/badge.svg?branch=v0.0
|
|
186
|
-
[test-url]: https://github.com/stdlib-js/string-first/actions/workflows/test.yml?query=branch:v0.0
|
|
195
|
+
[test-image]: https://github.com/stdlib-js/string-first/actions/workflows/test.yml/badge.svg?branch=v0.2.0
|
|
196
|
+
[test-url]: https://github.com/stdlib-js/string-first/actions/workflows/test.yml?query=branch:v0.2.0
|
|
187
197
|
|
|
188
198
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/string-first/main.svg
|
|
189
199
|
[coverage-url]: https://codecov.io/github/stdlib-js/string-first?branch=main
|
|
@@ -210,8 +220,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors].
|
|
|
210
220
|
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
211
221
|
|
|
212
222
|
[deno-url]: https://github.com/stdlib-js/string-first/tree/deno
|
|
223
|
+
[deno-readme]: https://github.com/stdlib-js/string-first/blob/deno/README.md
|
|
213
224
|
[umd-url]: https://github.com/stdlib-js/string-first/tree/umd
|
|
225
|
+
[umd-readme]: https://github.com/stdlib-js/string-first/blob/umd/README.md
|
|
214
226
|
[esm-url]: https://github.com/stdlib-js/string-first/tree/esm
|
|
227
|
+
[esm-readme]: https://github.com/stdlib-js/string-first/blob/esm/README.md
|
|
215
228
|
[branches-url]: https://github.com/stdlib-js/string-first/blob/main/branches.md
|
|
216
229
|
|
|
217
230
|
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/string-first/main/LICENSE
|
|
@@ -220,6 +233,12 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors].
|
|
|
220
233
|
|
|
221
234
|
[mdn-regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
|
|
222
235
|
|
|
236
|
+
<!-- <related-links> -->
|
|
237
|
+
|
|
238
|
+
[@stdlib/string/remove-first]: https://www.npmjs.com/package/@stdlib/string-remove-first
|
|
239
|
+
|
|
240
|
+
<!-- </related-links> -->
|
|
241
|
+
|
|
223
242
|
</section>
|
|
224
243
|
|
|
225
244
|
<!-- /.links -->
|
package/SECURITY.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";var g=function(i,e){return function(){return e||i((e={exports:{}}).exports,e),e.exports}};var v=g(function(P,m){
|
|
2
|
+
var d=require('@stdlib/assert-is-string/dist').isPrimitive,o=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,s=require('@stdlib/assert-is-plain-object/dist'),f=require('@stdlib/assert-has-own-property/dist'),p=require('@stdlib/array-base-assert-contains/dist').factory,l=require('@stdlib/string-base-first/dist'),c=require('@stdlib/string-base-first-code-point/dist'),h=require('@stdlib/string-base-first-grapheme-cluster/dist'),n=require('@stdlib/error-tools-fmtprodmsg/dist'),u=["grapheme","code_point","code_unit"],w={grapheme:h,code_point:c,code_unit:l},q=p(u);function b(i){var e,a,t,r;if(!d(i))throw new TypeError(n('1gp3F',i));if(t={mode:"grapheme"},a=arguments.length,a===1)r=1;else if(a===2){if(r=arguments[1],s(r))e=r,r=1;else if(!o(r))throw new TypeError(n('1gp3X',r))}else{if(r=arguments[1],!o(r))throw new TypeError(n('1gp3X',r));if(e=arguments[2],!s(e))throw new TypeError(n('1gp2V',e))}if(e&&f(e,"mode")&&(t.mode=e.mode,!q(t.mode)))throw new TypeError(n('1gpE1',"mode",u.join('", "'),t.mode));return w[t.mode](i,r)}m.exports=b
|
|
3
|
+
});var y=v();module.exports=y;
|
|
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 isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).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 firstCodeUnit = require( '@stdlib/string-base-first' );\nvar firstCodePoint = require( '@stdlib/string-base-first-code-point' );\nvar firstGraphemeCluster = require( '@stdlib/string-base-first-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': firstGraphemeCluster,\n\t'code_point': firstCodePoint,\n\t'code_unit': firstCodeUnit\n};\nvar isMode = contains( MODES );\n\n\n// MAIN //\n\n/**\n* Returns the first character(s) of a string.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} [n=1] - number of characters to return\n* @param {Options} [options] - options\n* @param {string} [options.mode=\"grapheme\"] - type of \"character\" to return (must be either `grapheme`, `code_point`, or `code_unit`)\n* @throws {TypeError} first argument must be a string\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @returns {string} output string\n*\n* @example\n* var out = first( 'last man standing' );\n* // returns 'l'\n*\n* @example\n* var out = first( 'presidential election' );\n* // returns 'p'\n*\n* @example\n* var out = first( 'javaScript' );\n* // returns 'j'\n*\n* @example\n* var out = first( 'Hidden Treasures' );\n* // returns 'H'\n*\n* @example\n* var out = first( '\uD83D\uDC36\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC30\uD83D\uDC38', 2 );\n* // returns '\uD83D\uDC36\uD83D\uDC2E'\n*\n* @example\n* var out = first( 'foo bar', 5 );\n* // returns 'foo b'\n*/\nfunction first( str ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar n;\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\topts = {\n\t\t'mode': 'grapheme'\n\t};\n\tnargs = arguments.length;\n\tif ( nargs === 1 ) {\n\t\tn = 1;\n\t} else if ( nargs === 2 ) {\n\t\tn = arguments[ 1 ];\n\t\tif ( isPlainObject( n ) ) {\n\t\t\toptions = n;\n\t\t\tn = 1;\n\t\t} else if ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t} else { // nargs > 2\n\t\tn = arguments[ 1 ];\n\t\tif ( !isNonNegativeInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', n ) );\n\t\t}\n\t\toptions = arguments[ 2 ];\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}\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\treturn FCNS[ opts.mode ]( str, n );\n}\n\n\n// EXPORTS //\n\nmodule.exports = first;\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* Return the first character(s) of a string.\n*\n* @module @stdlib/string-first\n*\n* @example\n* var first = require( '@stdlib/string-first' );\n*\n* var out = first( 'last man standing' );\n* // returns 'l'\n*\n* out = first( 'Hidden Treasures' );\n* // returns 'H';\n*\n* out = first( '\uD83D\uDC2E\uD83D\uDC37\uD83D\uDC38\uD83D\uDC35', 2 );\n* // returns '\uD83D\uDC2E\uD83D\uDC37'\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,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,oCAAqC,EAAE,QAC3DC,EAAgB,QAAS,2BAA4B,EACrDC,EAAiB,QAAS,sCAAuC,EACjEC,EAAuB,QAAS,4CAA6C,EAC7EC,EAAS,QAAS,uBAAwB,EAK1CC,EAAQ,CAAE,WAAY,aAAc,WAAY,EAChDC,EAAO,CACV,SAAYH,EACZ,WAAcD,EACd,UAAaD,CACd,EACIM,EAASP,EAAUK,CAAM,EA0C7B,SAASG,EAAOC,EAAM,CACrB,IAAIC,EACAC,EACAC,EACAC,EAEJ,GAAK,CAACjB,EAAUa,CAAI,EACnB,MAAM,IAAI,UAAWL,EAAQ,kEAAmEK,CAAI,CAAE,EAMvG,GAJAG,EAAO,CACN,KAAQ,UACT,EACAD,EAAQ,UAAU,OACbA,IAAU,EACdE,EAAI,UACOF,IAAU,GAErB,GADAE,EAAI,UAAW,CAAE,EACZf,EAAee,CAAE,EACrBH,EAAUG,EACVA,EAAI,UACO,CAAChB,EAAsBgB,CAAE,EACpC,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,MAE7G,CAEN,GADAA,EAAI,UAAW,CAAE,EACZ,CAAChB,EAAsBgB,CAAE,EAC7B,MAAM,IAAI,UAAWT,EAAQ,gFAAiFS,CAAE,CAAE,EAGnH,GADAH,EAAU,UAAW,CAAE,EAClB,CAACZ,EAAeY,CAAQ,EAC5B,MAAM,IAAI,UAAWN,EAAQ,qEAAsEM,CAAQ,CAAE,CAE/G,CACA,GAAKA,GACCX,EAAYW,EAAS,MAAO,IAChCE,EAAK,KAAOF,EAAQ,KACf,CAACH,EAAQK,EAAK,IAAK,GACvB,MAAM,IAAI,UAAWR,EAAQ,+EAAgF,OAAQC,EAAM,KAAM,MAAO,EAAGO,EAAK,IAAK,CAAE,EAI1J,OAAON,EAAMM,EAAK,IAAK,EAAGH,EAAKI,CAAE,CAClC,CAKAlB,EAAO,QAAUa,IC1FjB,IAAIM,EAAO,IAKX,OAAO,QAAUA",
|
|
6
|
+
"names": ["require_main", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isPlainObject", "hasOwnProp", "contains", "firstCodeUnit", "firstCodePoint", "firstGraphemeCluster", "format", "MODES", "FCNS", "isMode", "first", "str", "options", "nargs", "opts", "n", "main"]
|
|
7
|
+
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
// TypeScript Version:
|
|
19
|
+
// TypeScript Version: 4.1
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
/* eslint-disable @typescript-eslint/unified-signatures */
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Interface describing function options.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/string-first",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Return the first character(s) of a string.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -37,15 +37,15 @@
|
|
|
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-nonnegative-integer": "^0.0
|
|
43
|
-
"@stdlib/assert-is-plain-object": "^0.0
|
|
44
|
-
"@stdlib/assert-is-string": "^0.0
|
|
45
|
-
"@stdlib/string-base-first": "^0.0
|
|
46
|
-
"@stdlib/string-base-first-code-point": "^0.0
|
|
47
|
-
"@stdlib/string-base-first-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-nonnegative-integer": "^0.2.0",
|
|
43
|
+
"@stdlib/assert-is-plain-object": "^0.2.0",
|
|
44
|
+
"@stdlib/assert-is-string": "^0.2.0",
|
|
45
|
+
"@stdlib/string-base-first": "^0.2.0",
|
|
46
|
+
"@stdlib/string-base-first-code-point": "^0.2.0",
|
|
47
|
+
"@stdlib/string-base-first-grapheme-cluster": "^0.2.0",
|
|
48
|
+
"@stdlib/string-format": "^0.2.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|