@stdlib/string-first 0.0.1 → 0.1.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/CITATION.cff ADDED
@@ -0,0 +1,30 @@
1
+ cff-version: 1.2.0
2
+ title: stdlib
3
+ message: >-
4
+ If you use this software, please cite it using the
5
+ metadata from this file.
6
+
7
+ type: software
8
+
9
+ authors:
10
+ - name: The Stdlib Authors
11
+ url: https://github.com/stdlib-js/stdlib/graphs/contributors
12
+
13
+ repository-code: https://github.com/stdlib-js/stdlib
14
+ url: https://stdlib.io
15
+
16
+ abstract: |
17
+ Standard library for JavaScript and Node.js.
18
+
19
+ keywords:
20
+ - JavaScript
21
+ - Node.js
22
+ - TypeScript
23
+ - standard library
24
+ - scientific computing
25
+ - numerical computing
26
+ - statistical computing
27
+
28
+ license: Apache-2.0 AND BSL-1.0
29
+
30
+ date-released: 2016
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] -->
@@ -182,8 +193,8 @@ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
182
193
  [npm-image]: http://img.shields.io/npm/v/@stdlib/string-first.svg
183
194
  [npm-url]: https://npmjs.org/package/@stdlib/string-first
184
195
 
185
- [test-image]: https://github.com/stdlib-js/string-first/actions/workflows/test.yml/badge.svg?branch=v0.0.1
186
- [test-url]: https://github.com/stdlib-js/string-first/actions/workflows/test.yml?query=branch:v0.0.1
196
+ [test-image]: https://github.com/stdlib-js/string-first/actions/workflows/test.yml/badge.svg?branch=v0.1.0
197
+ [test-url]: https://github.com/stdlib-js/string-first/actions/workflows/test.yml?query=branch:v0.1.0
187
198
 
188
199
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/string-first/main.svg
189
200
  [coverage-url]: https://codecov.io/github/stdlib-js/string-first?branch=main
@@ -0,0 +1,3 @@
1
+ /// <reference path="../docs/types/index.d.ts" />
2
+ import first from '../docs/types/index';
3
+ export = first;
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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Object", "hasOwnProp", "contains", "firstCodeUnit", "firstCodePoint", "firstGraphemeCluster", "format", "MODES", "FCNS", "isMode", "first", "str", "options", "nargs", "opts", "n", "main"]
7
+ }
@@ -16,7 +16,7 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
- // TypeScript Version: 2.0
19
+ // TypeScript Version: 4.1
20
20
 
21
21
  // tslint:disable:unified-signatures
22
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/string-first",
3
- "version": "0.0.1",
3
+ "version": "0.1.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.1",
41
- "@stdlib/assert-has-own-property": "^0.0.7",
42
- "@stdlib/assert-is-nonnegative-integer": "^0.0.7",
43
- "@stdlib/assert-is-plain-object": "^0.0.7",
44
- "@stdlib/assert-is-string": "^0.0.8",
45
- "@stdlib/string-base-first": "^0.0.1",
46
- "@stdlib/string-base-first-code-point": "^0.0.1",
47
- "@stdlib/string-base-first-grapheme-cluster": "^0.0.1",
48
- "@stdlib/string-format": "^0.0.3"
40
+ "@stdlib/array-base-assert-contains": "^0.1.0",
41
+ "@stdlib/assert-has-own-property": "^0.1.0",
42
+ "@stdlib/assert-is-nonnegative-integer": "^0.1.0",
43
+ "@stdlib/assert-is-plain-object": "^0.1.0",
44
+ "@stdlib/assert-is-string": "^0.1.0",
45
+ "@stdlib/string-base-first": "^0.1.0",
46
+ "@stdlib/string-base-first-code-point": "^0.1.0",
47
+ "@stdlib/string-base-first-grapheme-cluster": "^0.1.0",
48
+ "@stdlib/string-format": "^0.1.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "tape": "git+https://github.com/kgryte/tape.git#fix/globby",