diff --git a/lib/node_modules/@stdlib/string/base/slice/README.md b/lib/node_modules/@stdlib/string/base/slice/README.md new file mode 100644 index 000000000000..df26d5565cd2 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/slice/README.md @@ -0,0 +1,102 @@ + + +# slice + +> Slice UTF-16 code units from a string. + +
+ +## Usage + +```javascript +var slice = require( '@stdlib/string/base/slice' ); +``` + +#### slice( str, start, end ) + +Slices UTF-16 code units from a string. + +```javascript +var out = slice( 'last man standing', 1, 17 ); +// returns 'ast man standing' + +out = slice( 'Hidden Treasures', 0, 6 ); +// returns 'Hidden' + +out = slice( 'foo bar', 2, 7 ); +// returns 'o bar' + +out = slice( 'foo bar', -1, 7 ); +// returns 'r' +``` + +The function accepts the following arguments: + +- **str**: input string. +- **start**: slice start index (inclusive). +- **end**: slice end index (exclusive). + +
+ + + +
+ +## Examples + + + +```javascript +var slice = require( '@stdlib/string/base/slice' ); + +var str = slice( 'presidential election', 1, 21 ); +// returns 'residential election' + +str = slice( 'JavaScript', 4, 10 ); +// returns 'Script' + +str = slice( 'The Last of the Mohicans', 5, 24 ); +// returns 'ast of the Mohicans' +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/string/base/slice/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/slice/benchmark/benchmark.js new file mode 100644 index 000000000000..4bb6202d135b --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/slice/benchmark/benchmark.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var slice = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var out; + var i; + + values = [ + 'beep boop', + 'foo bar', + 'xyz abc', + '🐶🐮🐷🐰🐸' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = slice( values[ i%values.length ], 1, 6 ); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/string/base/slice/docs/repl.txt b/lib/node_modules/@stdlib/string/base/slice/docs/repl.txt new file mode 100644 index 000000000000..926d543767b8 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/slice/docs/repl.txt @@ -0,0 +1,31 @@ + +{{alias}}( str, start, end ) + Slices UTF-16 code units from a string. + + Parameters + ---------- + str: string + Input string. + + start: integer + Slice start index (inclusive). + + end: integer + Slice end index (exclusive). + + Returns + ------- + out: string + Output string. + + Examples + -------- + > var out = {{alias}}( 'beep', 1, 4 ) + 'eep' + > out = {{alias}}( 'Boop', 1, 4 ) + 'oop' + > out = {{alias}}( 'foo bar', 5, 7 ) + 'ar' + + See Also + -------- diff --git a/lib/node_modules/@stdlib/string/base/slice/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/slice/docs/types/index.d.ts new file mode 100644 index 000000000000..373d1aa1f1ac --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/slice/docs/types/index.d.ts @@ -0,0 +1,58 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Slices UTF-16 code units from a string. +* +* @param str - input string +* @param start - slice start index (inclusive) +* @param end - slice end index (exclusive) +* @returns output string +* +* @example +* var out = slice( 'last man standing', 1, 17 ); +* // returns 'ast man standing' +* +* @example +* var out = slice( 'presidential election', 1, 21 ); +* // returns 'residential election' +* +* @example +* var out = slice( 'JavaScript', 4, 10 ); +* // returns 'Script' +* +* @example +* var out = slice( 'Hidden Treasures', 0, 6 ); +* // returns 'Hidden' +* +* @example +* var out = slice( 'foo bar', 2, 7 ); +* // returns 'ar' +* +* @example +* var out = slice( 'foo bar', -1, 7 ); +* // returns 'r' +*/ +declare function slice( str: string, start: number, end: number ): string; + + +// EXPORTS // + +export = slice; diff --git a/lib/node_modules/@stdlib/string/base/slice/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/slice/docs/types/test.ts new file mode 100644 index 000000000000..14ed8c813902 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/slice/docs/types/test.ts @@ -0,0 +1,68 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import slice = require( './index' ); + + +// TESTS // + +// The function returns a string... +{ + slice( 'abc', 1, 4 ); // $ExpectType string +} + +// The compiler throws an error if the function is provided a first argument that is not a string... +{ + slice( true, 1, 3 ); // $ExpectError + slice( false, 1, 3 ); // $ExpectError + slice( null, 1, 3 ); // $ExpectError + slice( undefined, 1, 3 ); // $ExpectError + slice( 5, 1, 3 ); // $ExpectError + slice( [], 1, 3 ); // $ExpectError + slice( {}, 1, 3 ); // $ExpectError + slice( ( x: number ): number => x, 1, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument that is not a number... +{ + slice( 'abc', true, 3 ); // $ExpectError + slice( 'abc', false, 3 ); // $ExpectError + slice( 'abc', null, 3 ); // $ExpectError + slice( 'abc', 'abc', 3 ); // $ExpectError + slice( 'abc', [], 3 ); // $ExpectError + slice( 'abc', {}, 3 ); // $ExpectError + slice( 'abc', ( x: number ): number => x, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument that is not a number... +{ + slice( 'abc', 1, true ); // $ExpectError + slice( 'abc', 1, false ); // $ExpectError + slice( 'abc', 1, null ); // $ExpectError + slice( 'abc', 1, 'abc' ); // $ExpectError + slice( 'abc', 1, [] ); // $ExpectError + slice( 'abc', 1, {} ); // $ExpectError + slice( 'abc', 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + slice(); // $ExpectError + slice( 'abc' ); // $ExpectError + slice( 'abc', 1, 2, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/string/base/slice/examples/index.js b/lib/node_modules/@stdlib/string/base/slice/examples/index.js new file mode 100644 index 000000000000..2709acdb70ae --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/slice/examples/index.js @@ -0,0 +1,30 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var slice = require( './../lib' ); + +console.log( slice( 'presidential election', 1, 21 ) ); +// => 'residential election' + +console.log( slice( 'JavaScript', 4, 10 ) ); +// => 'Script' + +console.log( slice( 'The Last of the Mohicans', 5, 24 ) ); +// => 'ast of the Mohicans' diff --git a/lib/node_modules/@stdlib/string/base/slice/lib/index.js b/lib/node_modules/@stdlib/string/base/slice/lib/index.js new file mode 100644 index 000000000000..85e27d32f44e --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/slice/lib/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Slice UTF-16 code units from a string. +* +* @module @stdlib/string/base/slice +* +* @example +* var slice = require( '@stdlib/string/base/slice' ); +* +* var out = slice( 'last man standing', 1, 17 ); +* // returns 'ast man standing' +* +* out = removeFirst( 'Hidden Treasures', 0, 6 ); +* // returns 'Hidden'; +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/string/base/slice/lib/main.js b/lib/node_modules/@stdlib/string/base/slice/lib/main.js new file mode 100644 index 000000000000..dfecb2c98ad3 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/slice/lib/main.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// VARIABLES // + +// Cache a reference to the built-in to prevent prototype mutation shenanigans: +var sliceString = String.prototype.slice; + + +// MAIN // + +/** +* Slices UTF-16 code units from a string. +* +* @param {string} str - input string +* @param {integer} start - slice start index (inclusive) +* @param {integer} end - slice end index (exclusive) +* @returns {string} input string +* +* @example +* var out = slice( 'last man standing', 1, 17 ); +* // returns 'ast man standing' +* +* out = slice( 'Hidden Treasures', 0, 6 ); +* // returns 'Hidden' +*/ +function slice( str, start, end ) { + return sliceString.call( str, start, end ); +} + + +// EXPORTS // + +module.exports = slice; diff --git a/lib/node_modules/@stdlib/string/base/slice/package.json b/lib/node_modules/@stdlib/string/base/slice/package.json new file mode 100644 index 000000000000..75e20ace9d65 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/slice/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/string/base/slice", + "version": "0.0.0", + "description": "Slice UTF-16 code units from a string.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdstring", + "utilities", + "utility", + "utils", + "util", + "string", + "str", + "base", + "slice", + "string.slice", + "codeunit", + "unicode" + ] +} diff --git a/lib/node_modules/@stdlib/string/base/slice/test/test.js b/lib/node_modules/@stdlib/string/base/slice/test/test.js new file mode 100644 index 000000000000..16b1c3e73229 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/slice/test/test.js @@ -0,0 +1,98 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var slice = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof slice, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 3', function test( t ) { + t.strictEqual( slice.length, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an empty string if provided a second argument greater or equal to string length', function test( t ) { + t.strictEqual( slice( 'hello world', 12, 4 ), '', 'returns expected value' ); + t.strictEqual( slice( 'hello world', 11, 4 ), '', 'returns expected value' ); + t.end(); +}); + +tape( 'the function slices the UTF-16 code units of a provided string (positive indices)', function test( t ) { + var out; + + out = slice( 'hello world', 1, 11 ); + t.strictEqual( out, 'ello world', 'returns expected value' ); + + out = slice( 'hello world', 7, 11 ); + t.strictEqual( out, 'orld', 'returns expected value' ); + + out = slice( '!!!', 1, 3 ); + t.strictEqual( out, '!!', 'returns expected value' ); + + out = slice( '!!!', 2, 3 ); + t.strictEqual( out, '!', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function slices the UTF-16 code units of a provided string (negative start index)', function test( t ) { + var out; + + out = slice( 'hello world', -4, 11 ); + t.strictEqual( out, 'orld', 'returns expected value' ); + + out = slice( 'hello world', -7, 11 ); + t.strictEqual( out, 'o world', 'returns expected value' ); + + out = slice( '!!!', -1, 3 ); + t.strictEqual( out, '!', 'returns expected value' ); + + out = slice( '!!!', -2, 3 ); + t.strictEqual( out, '!!', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function slices the UTF-16 code units of a provided string (negative end index)', function test( t ) { + var out; + + out = slice( 'hello world', 0, -8 ); + t.strictEqual( out, 'hel', 'returns expected value' ); + + out = slice( 'hello world', 4, -2 ); + t.strictEqual( out, 'o wor', 'returns expected value' ); + + out = slice( '!!!', 0, -1 ); + t.strictEqual( out, '!!', 'returns expected value' ); + + out = slice( '!!!', 1, -1 ); + t.strictEqual( out, '!', 'returns expected value' ); + + t.end(); +});