@stdlib/string-first 0.2.2 → 0.2.3

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 CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -178,7 +178,7 @@ See [LICENSE][stdlib-license].
178
178
 
179
179
  ## Copyright
180
180
 
181
- Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
181
+ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
182
182
 
183
183
  </section>
184
184
 
@@ -193,8 +193,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
193
193
  [npm-image]: http://img.shields.io/npm/v/@stdlib/string-first.svg
194
194
  [npm-url]: https://npmjs.org/package/@stdlib/string-first
195
195
 
196
- [test-image]: https://github.com/stdlib-js/string-first/actions/workflows/test.yml/badge.svg?branch=v0.2.2
197
- [test-url]: https://github.com/stdlib-js/string-first/actions/workflows/test.yml?query=branch:v0.2.2
196
+ [test-image]: https://github.com/stdlib-js/string-first/actions/workflows/test.yml/badge.svg?branch=v0.2.3
197
+ [test-url]: https://github.com/stdlib-js/string-first/actions/workflows/test.yml?query=branch:v0.2.3
198
198
 
199
199
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/string-first/main.svg
200
200
  [coverage-url]: https://codecov.io/github/stdlib-js/string-first?branch=main
@@ -206,8 +206,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
206
206
 
207
207
  -->
208
208
 
209
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
210
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
209
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
210
+ [chat-url]: https://stdlib.zulipchat.com
211
211
 
212
212
  [stdlib]: https://github.com/stdlib-js/stdlib
213
213
 
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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"],
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
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
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
7
  }
@@ -75,7 +75,7 @@ declare function first( str: string, n: number, options?: Options ): string;
75
75
  * var out = first( '🐶🐮🐷🐰🐸', {
76
76
  * 'mode': 'grapheme'
77
77
  * });
78
- * // returns '🐶🐮'
78
+ * // returns '🐶'
79
79
  */
80
80
  declare function first( str: string, options?: Options ): string;
81
81
 
package/lib/index.js CHANGED
@@ -30,7 +30,7 @@
30
30
  * // returns 'l'
31
31
  *
32
32
  * out = first( 'Hidden Treasures' );
33
- * // returns 'H';
33
+ * // returns 'H'
34
34
  *
35
35
  * out = first( '🐮🐷🐸🐵', 2 );
36
36
  * // returns '🐮🐷'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/string-first",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Return the first character(s) of a string.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -30,16 +30,16 @@
30
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@stdlib/array-base-assert-contains": "^0.2.1",
34
- "@stdlib/assert-has-own-property": "^0.2.2",
35
- "@stdlib/assert-is-nonnegative-integer": "^0.2.2",
36
- "@stdlib/assert-is-plain-object": "^0.2.2",
37
- "@stdlib/assert-is-string": "^0.2.2",
38
- "@stdlib/string-base-first": "^0.2.2",
39
- "@stdlib/string-base-first-code-point": "^0.2.2",
40
- "@stdlib/string-base-first-grapheme-cluster": "^0.2.2",
41
- "@stdlib/string-format": "^0.2.2",
42
- "@stdlib/error-tools-fmtprodmsg": "^0.2.2"
33
+ "@stdlib/array-base-assert-contains": "^0.2.2",
34
+ "@stdlib/assert-has-own-property": "^0.2.3",
35
+ "@stdlib/assert-is-nonnegative-integer": "^0.2.3",
36
+ "@stdlib/assert-is-plain-object": "^0.2.3",
37
+ "@stdlib/assert-is-string": "^0.2.3",
38
+ "@stdlib/string-base-first": "^0.2.3",
39
+ "@stdlib/string-base-first-code-point": "^0.2.3",
40
+ "@stdlib/string-base-first-grapheme-cluster": "^0.2.3",
41
+ "@stdlib/string-format": "^0.2.3",
42
+ "@stdlib/error-tools-fmtprodmsg": "^0.2.3"
43
43
  },
44
44
  "devDependencies": {},
45
45
  "engines": {