diff --git a/README.md b/README.md index 7389f3e..d439262 100644 --- a/README.md +++ b/README.md @@ -145,25 +145,25 @@ v = s.step; // returns -1 ``` -The function returns an error object if provided in invalid subsequence string. +The function returns an error object if provided an invalid subsequence string. ```javascript var s = seq2slice( '1:2:3:4', 10, false ); -// returns { 'code': 'ERR_INVALID_SUBSEQUENCE' } +// returns { 'code': 'ERR_SLICE_INVALID_SUBSEQUENCE' } ``` When `strict` is `true`, the function returns an error object if a subsequence string resolves to a slice exceeding index bounds. ```javascript var s = seq2slice( '10:20', 10, true ); -// returns { 'code': 'ERR_OUT_OF_BOUNDS' } +// returns { 'code': 'ERR_SLICE_OUT_OF_BOUNDS' } ``` A returned error object may have one of the following error codes: -- **ERR_INVALID_SUBSEQUENCE**: a subsequence string is invalid. -- **ERR_INVALID_INCREMENT**: a subsequence string must have a non-zero increment. -- **ERR_OUT_OF_BOUNDS**: a subsequence string resolves to a slice exceeding index bounds. +- **ERR_SLICE_INVALID_SUBSEQUENCE**: a subsequence string is invalid. +- **ERR_SLICE_INVALID_INCREMENT**: a subsequence string must have a non-zero increment. +- **ERR_SLICE_OUT_OF_BOUNDS**: a subsequence string resolves to a slice exceeding index bounds. @@ -337,8 +337,8 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [npm-image]: http://img.shields.io/npm/v/@stdlib/slice-base-seq2slice.svg [npm-url]: https://npmjs.org/package/@stdlib/slice-base-seq2slice -[test-image]: https://github.com/stdlib-js/slice-base-seq2slice/actions/workflows/test.yml/badge.svg?branch=main -[test-url]: https://github.com/stdlib-js/slice-base-seq2slice/actions/workflows/test.yml?query=branch:main +[test-image]: https://github.com/stdlib-js/slice-base-seq2slice/actions/workflows/test.yml/badge.svg?branch=v0.0.1 +[test-url]: https://github.com/stdlib-js/slice-base-seq2slice/actions/workflows/test.yml?query=branch:v0.0.1 [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/slice-base-seq2slice/main.svg [coverage-url]: https://codecov.io/github/stdlib-js/slice-base-seq2slice?branch=main diff --git a/dist/index.js b/dist/index.js index 99b14f6..ffce346 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,23 +1,23 @@ "use strict";var u=function(i,t){return function(){return t||i((t={exports:{}}).exports,t),t.exports}};var _=u(function(X,o){ var M=/(?:\s*-\s*)(?=\d+)(\d+)$/;o.exports=M -});var I=u(function(Y,p){ -var $=/(?:\s*\/\s*)(?=\d*\.?\d+)(\d*\.?\d+)$/;p.exports=$ +});var p=u(function(Y,I){ +var $=/(?:\s*\/\s*)(?=\d*\.?\d+)(\d*\.?\d+)$/;I.exports=$ });var c=u(function(Z,R){ -var N=require('@stdlib/math-base-special-floor/dist'),w=_(),A=I();function F(i,t,f,e){var s;if(i==="end")return t;if(s=i.match(w),s){if(i=t-parseInt(s[1],10),i<0){if(e)return-2;i=0}return i}return s=i.match(A),s?(i=parseFloat(s[1]),i<1?e?-2:-1:f&&t>0&&i!==1?N((t-1)/i):N(t/i)):-1}R.exports=F +var N=require('@stdlib/math-base-special-floor/dist'),w=_(),A=p();function F(i,t,f,e){var s;if(i==="end")return t;if(s=i.match(w),s){if(i=t-parseInt(s[1],10),i<0){if(e)return-2;i=0}return i}return s=i.match(A),s?(i=parseFloat(s[1]),i<1?e?-2:-1:f&&t>0&&i!==1?N((t-1)/i):N(t/i)):-1}R.exports=F });var v=u(function(rr,d){ var G=/\s*:\s*/;d.exports=G });var q=u(function(er,l){ var P=/^[-+]?[0-9]+$/;l.exports=P -});var x=u(function(tr,D){ +});var S=u(function(tr,D){ var b=/^end/;D.exports=b -});var S=u(function(ir,O){ -function Q(){return{code:"ERR_INVALID_SUBSEQUENCE"}}O.exports=Q -});var m=u(function(sr,h){ -function j(){return{code:"ERR_OUT_OF_BOUNDS"}}h.exports=j -});var g=u(function(ur,U){ -function k(){return{code:"ERR_INVALID_INCREMENT"}}U.exports=k +});var O=u(function(ir,x){ +function Q(){return{code:"ERR_SLICE_INVALID_SUBSEQUENCE"}}x.exports=Q +});var C=u(function(sr,h){ +function j(){return{code:"ERR_SLICE_OUT_OF_BOUNDS"}}h.exports=j +});var m=u(function(ur,L){ +function k(){return{code:"ERR_SLICE_INVALID_INCREMENT"}}L.exports=k });var B=u(function(fr,V){ -var C=require('@stdlib/slice-ctor/dist'),y=require('@stdlib/string-base-trim/dist'),L=c(),z=v(),E=q(),T=x(),a=S(),n=m(),H=g();function J(i,t,f){var e,s,r;if(e=y(i).split(z),s=e.length,s<2||s>3)return a();if(s===3)if(r=e[2],r.length===0)e[2]=1;else{if(E.test(r)===!1)return a();if(r=parseInt(r,10),r===0)return H();e[2]=r}else e.push(1);if(r=e[0],r.length===0)e[2]<0&&t>0?e[0]=t-1:e[0]=0;else if(T.test(r)){if(r=L(r,t,e[2]<0,f),r<0)return r===-2?n():a();e[2]<0&&r>=t&&(r-=1),e[0]=r}else if(E.test(r)){if(r=parseInt(r,10),r<0){if(r=t+r,r<0){if(f)return n();r=0}}else if(r>=t){if(f)return n();e[2]<0?r=t-1:r=t}e[0]=r}else return a();if(r=e[1],r.length===0)e[2]<0?e[1]=null:e[1]=t;else if(T.test(r)){if(r=L(r,t,e[2]<0,f),r<0)return r===-2?n():a();e[1]=r}else if(E.test(r)){if(r=parseInt(r,10),r<0){if(r=t+r,r<0)if(e[2]>0){if(f)return n();r=0}else{if(f&&r<-1)return n();r=null}}else if(r>t){if(f)return n();r=t}e[1]=r}else return a();return t===0?new C(0,0,e[2]):new C(e[0],e[1],e[2])}V.exports=J +var U=require('@stdlib/slice-ctor/dist'),y=require('@stdlib/string-base-trim/dist'),g=c(),z=v(),a=q(),T=S(),E=O(),n=C(),H=m();function J(i,t,f){var e,s,r;if(e=y(i).split(z),s=e.length,s<2||s>3)return E();if(s===3)if(r=e[2],r.length===0)e[2]=1;else{if(a.test(r)===!1)return E();if(r=parseInt(r,10),r===0)return H();e[2]=r}else e.push(1);if(r=e[0],r.length===0)e[2]<0&&t>0?e[0]=t-1:e[0]=0;else if(T.test(r)){if(r=g(r,t,e[2]<0,f),r<0)return r===-2?n():E();e[2]<0&&r>=t&&(r-=1),e[0]=r}else if(a.test(r)){if(r=parseInt(r,10),r<0){if(r=t+r,r<0){if(f)return n();r=0}}else if(r>=t){if(f)return n();e[2]<0?r=t-1:r=t}e[0]=r}else return E();if(r=e[1],r.length===0)e[2]<0?e[1]=null:e[1]=t;else if(T.test(r)){if(r=g(r,t,e[2]<0,f),r<0)return r===-2?n():E();e[1]=r}else if(a.test(r)){if(r=parseInt(r,10),r<0){if(r=t+r,r<0)if(e[2]>0){if(f)return n();r=0}else{if(f&&r<-1)return n();r=null}}else if(r>t){if(f)return n();r=t}e[1]=r}else return E();return t===0?new U(0,0,e[2]):new U(e[0],e[1],e[2])}V.exports=J });var K=B();module.exports=K; /** @license Apache-2.0 */ //# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map index f3d0b04..5377b0c 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../lib/re_end_minus.js", "../lib/re_end_divide.js", "../lib/resolve_end.js", "../lib/re_colon_sep.js", "../lib/re_integer.js", "../lib/re_end.js", "../lib/error_invalid_subsequence.js", "../lib/error_out_of_bounds.js", "../lib/error_invalid_increment.js", "../lib/main.js", "../lib/index.js"], - "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// MAIN //\n\n/**\n* Matches a subtraction operation following an 'end' character sequence.\n*\n* Regular expression: `/(?:\\s*-\\s*)(?=\\d+)(\\d+)?$/`\n*\n* - `(?:\\s*-\\s*)`\n*\n* - capture but do not remember a minus sign surrounded by any amount of whitespace\n*\n* - `(?=\\d+)`\n*\n* - but only match when the minus sign is followed by one or more digits\n*\n* - `(\\d+)`\n*\n* - capture one or more digits\n*\n* - `$`\n*\n* - end of input\n*\n* @private\n* @name RE_END_MINUS\n* @type {RegExp}\n*\n* @example\n* var m = 'end-2'.match( RE_END_MINUS );\n* // returns [...]\n*\n* var v = m[ 1 ];\n* // returns '2'\n*\n* m = 'end - 2'.match( RE_END_MINUS );\n* // returns [...]\n*\n* v = m[ 1 ];\n* // returns '2'\n*\n* m = 'end - 2.4'.match( RE_END_MINUS );\n* // returns null\n*/\nvar RE_END_MINUS = /(?:\\s*-\\s*)(?=\\d+)(\\d+)$/;\n\n\n// EXPORTS //\n\nmodule.exports = RE_END_MINUS;\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// MAIN //\n\n/**\n* Matches a division operation following an 'end' character sequence.\n*\n* Regular expression: `/(?:\\s*\\/\\s*)(?=\\d*\\.?\\d+)(\\d*\\.?\\d+)?$/`\n*\n* - `(?:\\s*\\/\\s*)`\n*\n* - capture but do not remember a divide sign surrounded by any amount of whitespace\n*\n* - `(?=\\d*\\.?\\d+)`\n*\n* - but only match when the minus divide is followed by one or more digits\n*\n* - `(\\d*\\.?\\d+)`\n*\n* - capture one or more digits\n*\n* - `$`\n*\n* - end of input\n*\n* @private\n* @name RE_END_DIVIDE\n* @type {RegExp}\n*\n* @example\n* var m = 'end/2'.match( RE_END_DIVIDE );\n* // returns [...]\n*\n* var v = m[ 1 ];\n* // returns '2'\n*\n* m = 'end / 2'.match( RE_END_DIVIDE );\n* // returns [...]\n*\n* v = m[ 1 ];\n* // returns '2'\n*\n* m = 'end / 2.4'.match( RE_END_DIVIDE );\n* // returns [...]\n*\n* v = m[ 1 ];\n* // returns '2.4'\n*/\nvar RE_END_DIVIDE = /(?:\\s*\\/\\s*)(?=\\d*\\.?\\d+)(\\d*\\.?\\d+)$/;\n\n\n// EXPORTS //\n\nmodule.exports = RE_END_DIVIDE;\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// MODULES //\n\nvar floor = require( '@stdlib/math-base-special-floor' );\nvar RE_END_MINUS = require( './re_end_minus.js' );\nvar RE_END_DIVIDE = require( './re_end_divide.js' );\n\n\n// MAIN //\n\n/**\n* Resolves an \"end\" index.\n*\n* ## Notes\n*\n* - The function returns `-1` if provided an invalid character sequence.\n* - The function returns `-2` if the resolved end index is out-of-bounds.\n*\n* @private\n* @param {string} v - character sequence containing the \"end\" keyword\n* @param {NonNegativeInteger} len - maximum number of elements allowed in the slice\n* @param {boolean} decrement - boolean indicating whether a subsequence has a negative decrement\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @returns {NonNegativeInteger} end index (exclusive)\n*\n* @example\n* var idx = resolveEnd( 'end', 10, false, false );\n* // returns 10\n*\n* idx = resolveEnd( 'end', 10, true, false );\n* // returns 10\n*\n* @example\n* var idx = resolveEnd( 'end-1', 10, false, false );\n* // returns 9\n*\n* idx = resolveEnd( 'end-1', 10, true, false );\n* // returns 9\n*\n* @example\n* var idx = resolveEnd( 'end-2', 10, false, false );\n* // returns 8\n*\n* idx = resolveEnd( 'end-2', 10, true, false );\n* // returns 8\n*\n* @example\n* var idx = resolveEnd( 'end/2', 10, false, false );\n* // returns 5\n*\n* idx = resolveEnd( 'end/2', 10, true, false );\n* // returns 4\n*\n* @example\n* var idx = resolveEnd( 'end/2', 11, false, false );\n* // returns 5\n*\n* idx = resolveEnd( 'end/2', 11, true, false );\n* // returns 5\n*\n* @example\n* var idx = resolveEnd( 'end/3', 10, false, false );\n* // returns 3\n*\n* idx = resolveEnd( 'end/3', 10, true, false );\n* // returns 3\n*\n* @example\n* var idx = resolveEnd( 'end/3', 11, false, false );\n* // returns 3\n*\n* idx = resolveEnd( 'end/3', 11, true, false );\n* // returns 3\n*\n* @example\n* var idx = resolveEnd( 'end/4', 10, false, false );\n* // returns 2\n*\n* idx = resolveEnd( 'end/4', 10, true, false );\n* // returns 2\n*\n* @example\n* var idx = resolveEnd( 'end/4', 11, false, false );\n* // returns 2\n*\n* idx = resolveEnd( 'end/4', 11, true, false );\n* // returns 2\n*\n* @example\n* var idx = resolveEnd( 'end/5', 10, false, false );\n* // returns 2\n*\n* idx = resolveEnd( 'end/5', 10, true, false );\n* // returns 1\n*\n* @example\n* var idx = resolveEnd( 'end/5', 11, false, false );\n* // returns 2\n*\n* idx = resolveEnd( 'end/5', 11, true, false );\n* // returns 2\n*\n* @example\n* var idx = resolveEnd( 'end-20', 10, false, false );\n* // returns 0\n*\n* idx = resolveEnd( 'end-20', 10, true, false );\n* // returns 0\n*\n* idx = resolveEnd( 'end-20', 10, true, true );\n* // returns -2\n*\n* @example\n* var idx = resolveEnd( 'end*2', 10, false, false );\n* // returns -1\n*\n* idx = resolveEnd( 'end*2', 10, true, false );\n* // returns -1\n*\n* @example\n* var idx = resolveEnd( 'end+1', 10, false, false );\n* // returns -1\n*\n* idx = resolveEnd( 'end+1', 10, true, false );\n* // returns -1\n*\n* @example\n* var idx = resolveEnd( 'end/0.5', 10, false, false );\n* // returns -1\n*\n* idx = resolveEnd( 'end/0.5', 10, true, false );\n* // returns -1\n*\n* idx = resolveEnd( 'end/0.5', 10, true, true );\n* // returns -2\n*/\nfunction resolveEnd( v, len, decrement, strict ) {\n\tvar tmp;\n\n\t// Check for the simple case where \"end\" refers to the last index (exclusive)...\n\tif ( v === 'end' ) {\n\t\treturn len;\n\t}\n\t// Check for a subtraction operation (e.g., `end-2`)...\n\ttmp = v.match( RE_END_MINUS );\n\tif ( tmp ) {\n\t\tv = len - parseInt( tmp[ 1 ], 10 );\n\n\t\t// If the computed index exceeds the index bounds, clamp to the first index...\n\t\tif ( v < 0 ) {\n\t\t\tif ( strict ) {\n\t\t\t\treturn -2; // return out-of-bounds error code\n\t\t\t}\n\t\t\tv = 0;\n\t\t}\n\t\treturn v;\n\t}\n\t// Check for a division operation (e.g., `end/2`)...\n\ttmp = v.match( RE_END_DIVIDE );\n\tif ( tmp ) {\n\t\tv = parseFloat( tmp[ 1 ] );\n\t\tif ( v < 1.0 ) {\n\t\t\treturn ( strict ) ? -2 : -1; // if `end/x > end`, then need to return out-of-bounds error code\n\t\t}\n\t\t// Handle division differently for increasing and decreasing increments in order to preserve the `:n + n: = :` identity and to satisfy user expectation that symmetry be maintained. The main issue being that, e.g., given a length 10 subsequence, `end/2` will yield `5`. Hence, `:end/2 + end/2: = :5 + :5 = :` (i.e., the first five elements (0,1,2,3,4) and the second five elements (5,6,7,8,9)); however, if increasing and decreasing are treated the same, `:end/2:-1 + end/2::-1 = :5:-1 + 5::-1 = :`, but the elements are not the same (i.e., the first elements (9,8,7,6) and the second elements (5,4,3,2,1)), due to the non-inclusive aspect of `j` in `i:j:k`. The slight adjustment (`len-1`) yields `:4:-1 + 4::-1 = :` and the slices (9,8,7,6,5) and (4,3,2,1,0), which better matches user expectation. For a length 11 subsequence, we get (0,1,2,3,4) and (5,6,7,8,9,10) for an increasing increment and (10,9,8,7,6) and (5,4,3,2,1,0), which seems fine given asymmetry in both cases.\n\t\tif ( decrement && len > 0 && v !== 1.0 ) { // note: avoid violating `end/1 = end` identity\n\t\t\treturn floor( (len-1) / v );\n\t\t}\n\t\treturn floor( len / v );\n\t}\n\t// The use of \"end\" includes invalid/unsupported operations...\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nmodule.exports = resolveEnd;\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// MAIN //\n\n/**\n* Matches a character sequence for a colon separator used within a provided subsequence string.\n*\n* Regular expression: `\\s*:\\s*`\n*\n* - `\\s*`\n*\n* - match zero or more whitespace characters\n*\n* - `:`\n*\n* - match the colon character exactly\n*\n* - `\\s*`\n*\n* - match zero or more whitespace characters\n*\n* ## Notes\n*\n* - The regular expression allows for whitespace to surround the `:` character in subsequence strings (e.g., '2 : 4 : 1' vs '2:4:1').\n*\n* @private\n* @name RE_COLON_SEP\n* @type {RegExp}\n*\n* @example\n* var parts = ':'.split( RE_COLON_SEP );\n* // returns [ '', '' ]\n*\n* parts = ' : '.split( RE_COLON_SEP );\n* // returns [ '', '' ]\n*/\nvar RE_COLON_SEP = /\\s*:\\s*/;\n\n\n// EXPORTS //\n\nmodule.exports = RE_COLON_SEP;\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// MAIN //\n\n/**\n* Matches a character sequence for an integer value.\n*\n* Regular expression: `/^[-+]?\\d+$/`\n*\n* - `^`\n*\n* - start of input\n*\n* - `[-+]?`\n*\n* - match a minus or plus sign (if present)\n*\n* - `\\d+`\n*\n* - match one or more digits\n*\n* - `$`\n*\n* - end of input\n*\n* @private\n* @name RE_INTEGER\n* @type {RegExp}\n*\n* @example\n* var bool = RE_INTEGER.test( '123' );\n* // returns true\n*\n* bool = RE_INTEGER.test( '12.3' );\n* // returns false\n*/\nvar RE_INTEGER = /^[-+]?[0-9]+$/;\n\n\n// EXPORTS //\n\nmodule.exports = RE_INTEGER;\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// MAIN //\n\n/**\n* Matches a character sequence which begins with 'end'.\n*\n* Regular expression: `/^end/`\n*\n* - `^`\n*\n* - start of input\n*\n* - `end`\n*\n* - match the character sequence 'end'\n*\n* @private\n* @name RE_END\n* @type {RegExp}\n*\n* @example\n* var bool = RE_END.test( 'end' );\n* // returns true\n*\n* bool = RE_END.test( 'foo end' );\n* // returns false\n*/\nvar RE_END = /^end/;\n\n\n// EXPORTS //\n\nmodule.exports = RE_END;\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// MAIN //\n\n/**\n* Returns an error object for an invalid subsequence string.\n*\n* @private\n* @returns {Object} error object\n*/\nfunction error() {\n\treturn {\n\t\t'code': 'ERR_INVALID_SUBSEQUENCE'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = error;\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// MAIN //\n\n/**\n* Returns an error object for a subsequence string resolving to a slice which exceeds index bounds.\n*\n* @private\n* @returns {Object} error object\n*/\nfunction error() {\n\treturn {\n\t\t'code': 'ERR_OUT_OF_BOUNDS'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = error;\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// MAIN //\n\n/**\n* Returns an error object for a subsequence string containing a zero increment.\n*\n* @private\n* @returns {Object} error object\n*/\nfunction error() {\n\treturn {\n\t\t'code': 'ERR_INVALID_INCREMENT'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = error;\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// MODULES //\n\nvar Slice = require( '@stdlib/slice-ctor' );\nvar trim = require( '@stdlib/string-base-trim' );\nvar resolveEnd = require( './resolve_end.js' );\nvar RE_COLON_SEP = require( './re_colon_sep.js' );\nvar RE_INTEGER = require( './re_integer.js' );\nvar RE_END = require( './re_end.js' );\nvar eInvalidSubsequence = require( './error_invalid_subsequence.js' );\nvar eOutOfBounds = require( './error_out_of_bounds.js' );\nvar eInvalidIncrement = require( './error_invalid_increment.js' );\n\n\n// MAIN //\n\n/**\n* Converts a subsequence string to a Slice object.\n*\n* ## Notes\n*\n* - A subsequence string has the following format:\n*\n* ```text\n* ::\n* ```\n*\n* where\n*\n* - If an `increment` is not specified, the default increment is `1`. An increment of zero is **not** allowed.\n* - The `start` index is **inclusive**.\n* - The `stop` index is **exclusive**.\n* - Both `start` and `stop` indices are _optional_. If not provided, `start` and `stop` default to index extremes. Which extremes correspond to which index depends on whether the `increment` is positive or negative.\n* - Both `start` and `stop` can be negative; in which case, the corresponding index is resolved by subtracting the respective value from the provided length `len`.\n* - Both `start` and `stop` can use the `end` keyword (e.g., `end-2::2`, `end-3:`, etc), which supports basic subtraction and division.\n* - The `end` keyword resolves to the provided length `len`. Thus, `:-1` is equivalent to `:end-1`, `:-2` is equivalent to `:end-2`, and so on and so forth. The exception is when performing a division operation when the `increment` is less than zero; in which case, `end` is equal to `len-1` in order to preserve user expectations when `end/d` equals a whole number and slicing from right-to-left. The result from a division operation is **rounded down** to the nearest integer value.\n*\n* - When `strict` is `false`, the resolved slice start is clamped to the slice index bounds (i.e., `[0, len)`).\n*\n* - When `strict` is `false`, the resolved slice end is upper bound clamped to `len` (i.e., one greater than the last possible index).\n*\n* - When the increment is negative, the resolved slice end value may be `null`, thus indicating that a non-empty slice should include the first index.\n*\n* - The function ensures that results satisfy the convention that `:n` combined with `n:` is equivalent to `:` (i.e., selecting all elements).\n*\n* - When `len` is zero, the function always returns a Slice object equivalent to `0:0:`.\n*\n* - The function returns an error object if provided in invalid subsequence string.\n*\n* - If `strict` is `true`, the function returns an error object if provided a subsequence string which exceeds index bounds.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} len - maximum number of elements allowed in the slice\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @returns {(Slice|Object)} Slice object or an error object\n*\n* @example\n* var s = seq2slice( '0:10:1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 0\n*\n* v = s.stop;\n* // returns 10\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* var s = seq2slice( '::-1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 9\n*\n* v = s.stop;\n* // returns null\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( ':0:-1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 9\n*\n* v = s.stop;\n* // returns 0\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( '4::-1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 4\n*\n* v = s.stop;\n* // returns null\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( '::', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 0\n*\n* v = s.stop;\n* // returns 10\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* var s = seq2slice( ':end:', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 0\n*\n* v = s.stop;\n* // returns 10\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* var s = seq2slice( 'end::-1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 9\n*\n* v = s.stop;\n* // returns null\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( 'end-2::-1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 8\n*\n* v = s.stop;\n* // returns null\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( 'end/2::-1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 4\n*\n* v = s.stop;\n* // returns null\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( 'end:end/2:-1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 9\n*\n* v = s.stop;\n* // returns 4\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( ':end/2:-1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 9\n*\n* v = s.stop;\n* // returns 4\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( ':end/2:1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 0\n*\n* v = s.stop;\n* // returns 5\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* var s = seq2slice( ':end/3', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 0\n*\n* v = s.stop;\n* // returns 3\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* var s = seq2slice( 'end/3::-1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 3\n*\n* v = s.stop;\n* // returns null\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( 'end/3::', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 3\n*\n* v = s.stop;\n* // returns 10\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* var s = seq2slice( 'end/3::', 9, false );\n* // returns \n*\n* var v = s.start;\n* // returns 3\n*\n* v = s.stop;\n* // returns 9\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* var s = seq2slice( 'end/3::-1', 9, false );\n* // returns \n*\n* var v = s.start;\n* // returns 2\n*\n* v = s.stop;\n* // returns null\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( '5:5', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 5\n*\n* v = s.stop;\n* // returns 5\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* var s = seq2slice( '5:5', 0, false );\n* // returns \n*\n* var v = s.start;\n* // returns 0\n*\n* v = s.stop;\n* // returns 0\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* var s = seq2slice( 'end:', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 10\n*\n* v = s.stop;\n* // returns 10\n*\n* v = s.step;\n* // returns 1\n*/\nfunction seq2slice( str, len, strict ) {\n\tvar parts;\n\tvar N;\n\tvar v;\n\n\tparts = trim( str ).split( RE_COLON_SEP );\n\tN = parts.length;\n\n\t// Disallow providing standalone components (e.g., '1', 'end', etc) and strings having too many components (e.g., '1:2:3:4')...\n\tif ( N < 2 || N > 3 ) {\n\t\treturn eInvalidSubsequence();\n\t}\n\n\t/* Increment */\n\n\t// Process the increment...\n\tif ( N === 3 ) {\n\t\tv = parts[ 2 ];\n\t\tif ( v.length === 0 ) { // empty increment\n\t\t\tparts[ 2 ] = 1; // default increment\n\t\t} else {\n\t\t\tif ( RE_INTEGER.test( v ) === false ) {\n\t\t\t\treturn eInvalidSubsequence();\n\t\t\t}\n\t\t\tv = parseInt( v, 10 );\n\t\t\tif ( v === 0 ) {\n\t\t\t\treturn eInvalidIncrement(); // increment cannot be zero\n\t\t\t}\n\t\t\tparts[ 2 ] = v;\n\t\t}\n\t} else {\n\t\tparts.push( 1 ); // default increment\n\t}\n\n\t/* Starting Index */\n\n\t// Process the starting index...\n\tv = parts[ 0 ];\n\n\t// Case: empty starting index\n\tif ( v.length === 0 ) {\n\t\t// If the increment is negative, we need to iterate from the last index...\n\t\tif ( parts[ 2 ] < 0 && len > 0 ) {\n\t\t\tparts[ 0 ] = len - 1;\n\t\t} else {\n\t\t\tparts[ 0 ] = 0; // default starting index (inclusive)\n\t\t}\n\t}\n\t// Case: use of the \"end\" keyword\n\telse if ( RE_END.test( v ) ) {\n\t\tv = resolveEnd( v, len, parts[ 2 ] < 0, strict );\n\t\tif ( v < 0 ) {\n\t\t\tif ( v === -2 ) {\n\t\t\t\treturn eOutOfBounds();\n\t\t\t}\n\t\t\treturn eInvalidSubsequence();\n\t\t}\n\t\tif ( parts[ 2 ] < 0 && v >= len ) {\n\t\t\tv -= 1; // clamp to the last index\n\t\t}\n\t\tparts[ 0 ] = v;\n\t}\n\t// Case: integer character sequence\n\telse if ( RE_INTEGER.test( v ) ) {\n\t\tv = parseInt( v, 10 );\n\n\t\t// Check whether we need to resolve the starting index relative to the last index...\n\t\tif ( v < 0 ) {\n\t\t\tv = len + v;\n\n\t\t\t// If the computed index exceeds the index bounds, clamp to the first index...\n\t\t\tif ( v < 0 ) {\n\t\t\t\tif ( strict ) {\n\t\t\t\t\treturn eOutOfBounds();\n\t\t\t\t}\n\t\t\t\tv = 0;\n\t\t\t}\n\t\t}\n\t\t// If the index exceeds the index bounds, clamp to the starting index...\n\t\telse if ( v >= len ) {\n\t\t\tif ( strict ) {\n\t\t\t\treturn eOutOfBounds();\n\t\t\t}\n\t\t\t// If the increment is negative, clamp to the last index (inclusive)...\n\t\t\tif ( parts[ 2 ] < 0 ) {\n\t\t\t\tv = len - 1;\n\t\t\t}\n\t\t\t// If the increment is positive, clamp to the \"index\" following the last index...\n\t\t\telse {\n\t\t\t\tv = len;\n\t\t\t}\n\t\t}\n\t\tparts[ 0 ] = v;\n\t}\n\t// Case: invalid/unsupported characters/operations\n\telse {\n\t\treturn eInvalidSubsequence();\n\t}\n\n\t/* Ending Index */\n\n\t// Processing the ending index...\n\tv = parts[ 1 ];\n\n\t// Case: empty ending index\n\tif ( v.length === 0 ) {\n\t\t// If the increment is negative, we need to iterate toward the first index...\n\t\tif ( parts[ 2 ] < 0 ) {\n\t\t\tparts[ 1 ] = null;\n\t\t} else {\n\t\t\tparts[ 1 ] = len; // default ending index (exclusive)\n\t\t}\n\t}\n\t// Case: use of the \"end\" keyword\n\telse if ( RE_END.test( v ) ) {\n\t\tv = resolveEnd( v, len, parts[ 2 ] < 0, strict );\n\t\tif ( v < 0 ) {\n\t\t\tif ( v === -2 ) {\n\t\t\t\treturn eOutOfBounds();\n\t\t\t}\n\t\t\treturn eInvalidSubsequence();\n\t\t}\n\t\tparts[ 1 ] = v;\n\t}\n\t// Case: integer character sequence\n\telse if ( RE_INTEGER.test( v ) ) {\n\t\tv = parseInt( v, 10 );\n\n\t\t// Check whether we need to resolve the starting index relative to the last index...\n\t\tif ( v < 0 ) {\n\t\t\tv = len + v;\n\n\t\t\t// Check whether the computed index exceeds the index bounds...\n\t\t\tif ( v < 0 ) {\n\t\t\t\t// If the increment is positive, clamp the ending index to the first index (exclusive)...\n\t\t\t\tif ( parts[ 2 ] > 0 ) {\n\t\t\t\t\tif ( strict ) {\n\t\t\t\t\t\treturn eOutOfBounds();\n\t\t\t\t\t}\n\t\t\t\t\tv = 0;\n\t\t\t\t} else {\n\t\t\t\t\t// If the increment is negative, the ending index should resolve to the first index (inclusive)...\n\t\t\t\t\tif ( strict && v < -1 ) {\n\t\t\t\t\t\treturn eOutOfBounds();\n\t\t\t\t\t}\n\t\t\t\t\tv = null;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// If the index exceeds the index bounds, clamp to the last \"index\" (exclusive)...\n\t\telse if ( v > len ) {\n\t\t\tif ( strict ) {\n\t\t\t\treturn eOutOfBounds();\n\t\t\t}\n\t\t\tv = len;\n\t\t}\n\t\tparts[ 1 ] = v;\n\t}\n\t// Case: invalid/unsupported characters/operations\n\telse {\n\t\treturn eInvalidSubsequence();\n\t}\n\n\t// Handle empty slice (note: this is at the end rather than at the beginning in order to ensure that `start` and `stop` are always validated)...\n\tif ( len === 0 ) {\n\t\treturn new Slice( 0, 0, parts[ 2 ] );\n\t}\n\n\treturn new Slice( parts[ 0 ], parts[ 1 ], parts[ 2 ] );\n}\n\n\n// EXPORTS //\n\nmodule.exports = seq2slice;\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* Convert a subsequence string to a Slice object.\n*\n* @module @stdlib/slice-base-seq2slice\n*\n* @example\n* var seq2slice = require( '@stdlib/slice-base-seq2slice' );\n*\n* var s = seq2slice( '0:10:1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 0\n*\n* v = s.stop;\n* // returns 10\n*\n* v = s.step;\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,IAAIC,EAAe,2BAKnBD,EAAO,QAAUC,ICpEjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAkEA,IAAIC,EAAgB,wCAKpBD,EAAO,QAAUC,ICvEjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EACnDC,EAAe,IACfC,EAAgB,IAmIpB,SAASC,EAAYC,EAAGC,EAAKC,EAAWC,EAAS,CAChD,I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AO,CAAE,EAAI,EACjBE,EAAIJ,EAAM,EAIVI,EAAIJ,CAEN,CACAE,EAAO,CAAE,EAAIE,CACd,KAGC,QAAOT,EAAoB,EAS5B,GAHAS,EAAIF,EAAO,CAAE,EAGRE,EAAE,SAAW,EAEZF,EAAO,CAAE,EAAI,EACjBA,EAAO,CAAE,EAAI,KAEbA,EAAO,CAAE,EAAIF,UAILN,EAAO,KAAMU,CAAE,EAAI,CAE5B,GADAA,EAAIb,EAAYa,EAAGJ,EAAKE,EAAO,CAAE,EAAI,EAAGD,CAAO,EAC1CG,EAAI,EACR,OAAKA,IAAM,GACHR,EAAa,EAEdD,EAAoB,EAE5BO,EAAO,CAAE,EAAIE,CACd,SAEUX,EAAW,KAAMW,CAAE,EAAI,CAIhC,GAHAA,EAAI,SAAUA,EAAG,EAAG,EAGfA,EAAI,GAIR,GAHAA,EAAIJ,EAAMI,EAGLA,EAAI,EAER,GAAKF,EAAO,CAAE,EAAI,EAAI,CACrB,GAAKD,EACJ,OAAOL,EAAa,EAErBQ,EAAI,CACL,KAAO,CAEN,GAAKH,GAAUG,EAAI,GAClB,OAAOR,EAAa,EAErBQ,EAAI,IACL,UAIQA,EAAIJ,EAAM,CACnB,GAAKC,EACJ,OAAOL,EAAa,EAErBQ,EAAIJ,CACL,CACAE,EAAO,CAAE,EAAIE,CACd,KAGC,QAAOT,EAAoB,EAI5B,OAAKK,IAAQ,EACL,IAAIX,EAAO,EAAG,EAAGa,EAAO,CAAE,CAAE,EAG7B,IAAIb,EAAOa,EAAO,CAAE,EAAGA,EAAO,CAAE,EAAGA,EAAO,CAAE,CAAE,CACtD,CAKAd,EAAO,QAAUU,ICldjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", + "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// MAIN //\n\n/**\n* Matches a subtraction operation following an 'end' character sequence.\n*\n* Regular expression: `/(?:\\s*-\\s*)(?=\\d+)(\\d+)?$/`\n*\n* - `(?:\\s*-\\s*)`\n*\n* - capture but do not remember a minus sign surrounded by any amount of whitespace\n*\n* - `(?=\\d+)`\n*\n* - but only match when the minus sign is followed by one or more digits\n*\n* - `(\\d+)`\n*\n* - capture one or more digits\n*\n* - `$`\n*\n* - end of input\n*\n* @private\n* @name RE_END_MINUS\n* @type {RegExp}\n*\n* @example\n* var m = 'end-2'.match( RE_END_MINUS );\n* // returns [...]\n*\n* var v = m[ 1 ];\n* // returns '2'\n*\n* m = 'end - 2'.match( RE_END_MINUS );\n* // returns [...]\n*\n* v = m[ 1 ];\n* // returns '2'\n*\n* m = 'end - 2.4'.match( RE_END_MINUS );\n* // returns null\n*/\nvar RE_END_MINUS = /(?:\\s*-\\s*)(?=\\d+)(\\d+)$/;\n\n\n// EXPORTS //\n\nmodule.exports = RE_END_MINUS;\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// MAIN //\n\n/**\n* Matches a division operation following an 'end' character sequence.\n*\n* Regular expression: `/(?:\\s*\\/\\s*)(?=\\d*\\.?\\d+)(\\d*\\.?\\d+)?$/`\n*\n* - `(?:\\s*\\/\\s*)`\n*\n* - capture but do not remember a divide sign surrounded by any amount of whitespace\n*\n* - `(?=\\d*\\.?\\d+)`\n*\n* - but only match when the minus divide is followed by one or more digits\n*\n* - `(\\d*\\.?\\d+)`\n*\n* - capture one or more digits\n*\n* - `$`\n*\n* - end of input\n*\n* @private\n* @name RE_END_DIVIDE\n* @type {RegExp}\n*\n* @example\n* var m = 'end/2'.match( RE_END_DIVIDE );\n* // returns [...]\n*\n* var v = m[ 1 ];\n* // returns '2'\n*\n* m = 'end / 2'.match( RE_END_DIVIDE );\n* // returns [...]\n*\n* v = m[ 1 ];\n* // returns '2'\n*\n* m = 'end / 2.4'.match( RE_END_DIVIDE );\n* // returns [...]\n*\n* v = m[ 1 ];\n* // returns '2.4'\n*/\nvar RE_END_DIVIDE = /(?:\\s*\\/\\s*)(?=\\d*\\.?\\d+)(\\d*\\.?\\d+)$/;\n\n\n// EXPORTS //\n\nmodule.exports = RE_END_DIVIDE;\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// MODULES //\n\nvar floor = require( '@stdlib/math-base-special-floor' );\nvar RE_END_MINUS = require( './re_end_minus.js' );\nvar RE_END_DIVIDE = require( './re_end_divide.js' );\n\n\n// MAIN //\n\n/**\n* Resolves an \"end\" index.\n*\n* ## Notes\n*\n* - The function returns `-1` if provided an invalid character sequence.\n* - The function returns `-2` if the resolved end index is out-of-bounds.\n*\n* @private\n* @param {string} v - character sequence containing the \"end\" keyword\n* @param {NonNegativeInteger} len - maximum number of elements allowed in the slice\n* @param {boolean} decrement - boolean indicating whether a subsequence has a negative decrement\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @returns {NonNegativeInteger} end index (exclusive)\n*\n* @example\n* var idx = resolveEnd( 'end', 10, false, false );\n* // returns 10\n*\n* idx = resolveEnd( 'end', 10, true, false );\n* // returns 10\n*\n* @example\n* var idx = resolveEnd( 'end-1', 10, false, false );\n* // returns 9\n*\n* idx = resolveEnd( 'end-1', 10, true, false );\n* // returns 9\n*\n* @example\n* var idx = resolveEnd( 'end-2', 10, false, false );\n* // returns 8\n*\n* idx = resolveEnd( 'end-2', 10, true, false );\n* // returns 8\n*\n* @example\n* var idx = resolveEnd( 'end/2', 10, false, false );\n* // returns 5\n*\n* idx = resolveEnd( 'end/2', 10, true, false );\n* // returns 4\n*\n* @example\n* var idx = resolveEnd( 'end/2', 11, false, false );\n* // returns 5\n*\n* idx = resolveEnd( 'end/2', 11, true, false );\n* // returns 5\n*\n* @example\n* var idx = resolveEnd( 'end/3', 10, false, false );\n* // returns 3\n*\n* idx = resolveEnd( 'end/3', 10, true, false );\n* // returns 3\n*\n* @example\n* var idx = resolveEnd( 'end/3', 11, false, false );\n* // returns 3\n*\n* idx = resolveEnd( 'end/3', 11, true, false );\n* // returns 3\n*\n* @example\n* var idx = resolveEnd( 'end/4', 10, false, false );\n* // returns 2\n*\n* idx = resolveEnd( 'end/4', 10, true, false );\n* // returns 2\n*\n* @example\n* var idx = resolveEnd( 'end/4', 11, false, false );\n* // returns 2\n*\n* idx = resolveEnd( 'end/4', 11, true, false );\n* // returns 2\n*\n* @example\n* var idx = resolveEnd( 'end/5', 10, false, false );\n* // returns 2\n*\n* idx = resolveEnd( 'end/5', 10, true, false );\n* // returns 1\n*\n* @example\n* var idx = resolveEnd( 'end/5', 11, false, false );\n* // returns 2\n*\n* idx = resolveEnd( 'end/5', 11, true, false );\n* // returns 2\n*\n* @example\n* var idx = resolveEnd( 'end-20', 10, false, false );\n* // returns 0\n*\n* idx = resolveEnd( 'end-20', 10, true, false );\n* // returns 0\n*\n* idx = resolveEnd( 'end-20', 10, true, true );\n* // returns -2\n*\n* @example\n* var idx = resolveEnd( 'end*2', 10, false, false );\n* // returns -1\n*\n* idx = resolveEnd( 'end*2', 10, true, false );\n* // returns -1\n*\n* @example\n* var idx = resolveEnd( 'end+1', 10, false, false );\n* // returns -1\n*\n* idx = resolveEnd( 'end+1', 10, true, false );\n* // returns -1\n*\n* @example\n* var idx = resolveEnd( 'end/0.5', 10, false, false );\n* // returns -1\n*\n* idx = resolveEnd( 'end/0.5', 10, true, false );\n* // returns -1\n*\n* idx = resolveEnd( 'end/0.5', 10, true, true );\n* // returns -2\n*/\nfunction resolveEnd( v, len, decrement, strict ) {\n\tvar tmp;\n\n\t// Check for the simple case where \"end\" refers to the last index (exclusive)...\n\tif ( v === 'end' ) {\n\t\treturn len;\n\t}\n\t// Check for a subtraction operation (e.g., `end-2`)...\n\ttmp = v.match( RE_END_MINUS );\n\tif ( tmp ) {\n\t\tv = len - parseInt( tmp[ 1 ], 10 );\n\n\t\t// If the computed index exceeds the index bounds, clamp to the first index...\n\t\tif ( v < 0 ) {\n\t\t\tif ( strict ) {\n\t\t\t\treturn -2; // return out-of-bounds error code\n\t\t\t}\n\t\t\tv = 0;\n\t\t}\n\t\treturn v;\n\t}\n\t// Check for a division operation (e.g., `end/2`)...\n\ttmp = v.match( RE_END_DIVIDE );\n\tif ( tmp ) {\n\t\tv = parseFloat( tmp[ 1 ] );\n\t\tif ( v < 1.0 ) {\n\t\t\treturn ( strict ) ? -2 : -1; // if `end/x > end`, then need to return out-of-bounds error code\n\t\t}\n\t\t// Handle division differently for increasing and decreasing increments in order to preserve the `:n + n: = :` identity and to satisfy user expectation that symmetry be maintained. The main issue being that, e.g., given a length 10 subsequence, `end/2` will yield `5`. Hence, `:end/2 + end/2: = :5 + :5 = :` (i.e., the first five elements (0,1,2,3,4) and the second five elements (5,6,7,8,9)); however, if increasing and decreasing are treated the same, `:end/2:-1 + end/2::-1 = :5:-1 + 5::-1 = :`, but the elements are not the same (i.e., the first elements (9,8,7,6) and the second elements (5,4,3,2,1)), due to the non-inclusive aspect of `j` in `i:j:k`. The slight adjustment (`len-1`) yields `:4:-1 + 4::-1 = :` and the slices (9,8,7,6,5) and (4,3,2,1,0), which better matches user expectation. For a length 11 subsequence, we get (0,1,2,3,4) and (5,6,7,8,9,10) for an increasing increment and (10,9,8,7,6) and (5,4,3,2,1,0), which seems fine given asymmetry in both cases.\n\t\tif ( decrement && len > 0 && v !== 1.0 ) { // note: avoid violating `end/1 = end` identity\n\t\t\treturn floor( (len-1) / v );\n\t\t}\n\t\treturn floor( len / v );\n\t}\n\t// The use of \"end\" includes invalid/unsupported operations...\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nmodule.exports = resolveEnd;\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// MAIN //\n\n/**\n* Matches a character sequence for a colon separator used within a provided subsequence string.\n*\n* Regular expression: `\\s*:\\s*`\n*\n* - `\\s*`\n*\n* - match zero or more whitespace characters\n*\n* - `:`\n*\n* - match the colon character exactly\n*\n* - `\\s*`\n*\n* - match zero or more whitespace characters\n*\n* ## Notes\n*\n* - The regular expression allows for whitespace to surround the `:` character in subsequence strings (e.g., '2 : 4 : 1' vs '2:4:1').\n*\n* @private\n* @name RE_COLON_SEP\n* @type {RegExp}\n*\n* @example\n* var parts = ':'.split( RE_COLON_SEP );\n* // returns [ '', '' ]\n*\n* parts = ' : '.split( RE_COLON_SEP );\n* // returns [ '', '' ]\n*/\nvar RE_COLON_SEP = /\\s*:\\s*/;\n\n\n// EXPORTS //\n\nmodule.exports = RE_COLON_SEP;\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// MAIN //\n\n/**\n* Matches a character sequence for an integer value.\n*\n* Regular expression: `/^[-+]?\\d+$/`\n*\n* - `^`\n*\n* - start of input\n*\n* - `[-+]?`\n*\n* - match a minus or plus sign (if present)\n*\n* - `\\d+`\n*\n* - match one or more digits\n*\n* - `$`\n*\n* - end of input\n*\n* @private\n* @name RE_INTEGER\n* @type {RegExp}\n*\n* @example\n* var bool = RE_INTEGER.test( '123' );\n* // returns true\n*\n* bool = RE_INTEGER.test( '12.3' );\n* // returns false\n*/\nvar RE_INTEGER = /^[-+]?[0-9]+$/;\n\n\n// EXPORTS //\n\nmodule.exports = RE_INTEGER;\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// MAIN //\n\n/**\n* Matches a character sequence which begins with 'end'.\n*\n* Regular expression: `/^end/`\n*\n* - `^`\n*\n* - start of input\n*\n* - `end`\n*\n* - match the character sequence 'end'\n*\n* @private\n* @name RE_END\n* @type {RegExp}\n*\n* @example\n* var bool = RE_END.test( 'end' );\n* // returns true\n*\n* bool = RE_END.test( 'foo end' );\n* // returns false\n*/\nvar RE_END = /^end/;\n\n\n// EXPORTS //\n\nmodule.exports = RE_END;\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// MAIN //\n\n/**\n* Returns an error object for an invalid subsequence string.\n*\n* @private\n* @returns {Object} error object\n*/\nfunction error() {\n\treturn {\n\t\t'code': 'ERR_SLICE_INVALID_SUBSEQUENCE'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = error;\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// MAIN //\n\n/**\n* Returns an error object for a subsequence string resolving to a slice which exceeds index bounds.\n*\n* @private\n* @returns {Object} error object\n*/\nfunction error() {\n\treturn {\n\t\t'code': 'ERR_SLICE_OUT_OF_BOUNDS'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = error;\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// MAIN //\n\n/**\n* Returns an error object for a subsequence string containing a zero increment.\n*\n* @private\n* @returns {Object} error object\n*/\nfunction error() {\n\treturn {\n\t\t'code': 'ERR_SLICE_INVALID_INCREMENT'\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = error;\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// MODULES //\n\nvar Slice = require( '@stdlib/slice-ctor' );\nvar trim = require( '@stdlib/string-base-trim' );\nvar resolveEnd = require( './resolve_end.js' );\nvar RE_COLON_SEP = require( './re_colon_sep.js' );\nvar RE_INTEGER = require( './re_integer.js' );\nvar RE_END = require( './re_end.js' );\nvar eInvalidSubsequence = require( './error_invalid_subsequence.js' );\nvar eOutOfBounds = require( './error_out_of_bounds.js' );\nvar eInvalidIncrement = require( './error_invalid_increment.js' );\n\n\n// MAIN //\n\n/**\n* Converts a subsequence string to a Slice object.\n*\n* ## Notes\n*\n* - A subsequence string has the following format:\n*\n* ```text\n* ::\n* ```\n*\n* where\n*\n* - If an `increment` is not specified, the default increment is `1`. An increment of zero is **not** allowed.\n* - The `start` index is **inclusive**.\n* - The `stop` index is **exclusive**.\n* - Both `start` and `stop` indices are _optional_. If not provided, `start` and `stop` default to index extremes. Which extremes correspond to which index depends on whether the `increment` is positive or negative.\n* - Both `start` and `stop` can be negative; in which case, the corresponding index is resolved by subtracting the respective value from the provided length `len`.\n* - Both `start` and `stop` can use the `end` keyword (e.g., `end-2::2`, `end-3:`, etc), which supports basic subtraction and division.\n* - The `end` keyword resolves to the provided length `len`. Thus, `:-1` is equivalent to `:end-1`, `:-2` is equivalent to `:end-2`, and so on and so forth. The exception is when performing a division operation when the `increment` is less than zero; in which case, `end` is equal to `len-1` in order to preserve user expectations when `end/d` equals a whole number and slicing from right-to-left. The result from a division operation is **rounded down** to the nearest integer value.\n*\n* - When `strict` is `false`, the resolved slice start is clamped to the slice index bounds (i.e., `[0, len)`).\n*\n* - When `strict` is `false`, the resolved slice end is upper bound clamped to `len` (i.e., one greater than the last possible index).\n*\n* - When the increment is negative, the resolved slice end value may be `null`, thus indicating that a non-empty slice should include the first index.\n*\n* - The function ensures that results satisfy the convention that `:n` combined with `n:` is equivalent to `:` (i.e., selecting all elements).\n*\n* - When `len` is zero, the function always returns a Slice object equivalent to `0:0:`.\n*\n* - The function returns an error object if provided an invalid subsequence string.\n*\n* - If `strict` is `true`, the function returns an error object if provided a subsequence string which exceeds index bounds.\n*\n* @param {string} str - input string\n* @param {NonNegativeInteger} len - maximum number of elements allowed in the slice\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @returns {(Slice|Object)} Slice object or an error object\n*\n* @example\n* var s = seq2slice( '0:10:1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 0\n*\n* v = s.stop;\n* // returns 10\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* var s = seq2slice( '::-1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 9\n*\n* v = s.stop;\n* // returns null\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( ':0:-1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 9\n*\n* v = s.stop;\n* // returns 0\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( '4::-1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 4\n*\n* v = s.stop;\n* // returns null\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( '::', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 0\n*\n* v = s.stop;\n* // returns 10\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* var s = seq2slice( ':end:', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 0\n*\n* v = s.stop;\n* // returns 10\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* var s = seq2slice( 'end::-1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 9\n*\n* v = s.stop;\n* // returns null\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( 'end-2::-1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 8\n*\n* v = s.stop;\n* // returns null\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( 'end/2::-1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 4\n*\n* v = s.stop;\n* // returns null\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( 'end:end/2:-1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 9\n*\n* v = s.stop;\n* // returns 4\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( ':end/2:-1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 9\n*\n* v = s.stop;\n* // returns 4\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( ':end/2:1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 0\n*\n* v = s.stop;\n* // returns 5\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* var s = seq2slice( ':end/3', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 0\n*\n* v = s.stop;\n* // returns 3\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* var s = seq2slice( 'end/3::-1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 3\n*\n* v = s.stop;\n* // returns null\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( 'end/3::', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 3\n*\n* v = s.stop;\n* // returns 10\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* var s = seq2slice( 'end/3::', 9, false );\n* // returns \n*\n* var v = s.start;\n* // returns 3\n*\n* v = s.stop;\n* // returns 9\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* var s = seq2slice( 'end/3::-1', 9, false );\n* // returns \n*\n* var v = s.start;\n* // returns 2\n*\n* v = s.stop;\n* // returns null\n*\n* v = s.step;\n* // returns -1\n*\n* @example\n* var s = seq2slice( '5:5', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 5\n*\n* v = s.stop;\n* // returns 5\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* var s = seq2slice( '5:5', 0, false );\n* // returns \n*\n* var v = s.start;\n* // returns 0\n*\n* v = s.stop;\n* // returns 0\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* var s = seq2slice( 'end:', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 10\n*\n* v = s.stop;\n* // returns 10\n*\n* v = s.step;\n* // returns 1\n*/\nfunction seq2slice( str, len, strict ) {\n\tvar parts;\n\tvar N;\n\tvar v;\n\n\tparts = trim( str ).split( RE_COLON_SEP );\n\tN = parts.length;\n\n\t// Disallow providing standalone components (e.g., '1', 'end', etc) and strings having too many components (e.g., '1:2:3:4')...\n\tif ( N < 2 || N > 3 ) {\n\t\treturn eInvalidSubsequence();\n\t}\n\n\t/* Increment */\n\n\t// Process the increment...\n\tif ( N === 3 ) {\n\t\tv = parts[ 2 ];\n\t\tif ( v.length === 0 ) { // empty increment\n\t\t\tparts[ 2 ] = 1; // default increment\n\t\t} else {\n\t\t\tif ( RE_INTEGER.test( v ) === false ) {\n\t\t\t\treturn eInvalidSubsequence();\n\t\t\t}\n\t\t\tv = parseInt( v, 10 );\n\t\t\tif ( v === 0 ) {\n\t\t\t\treturn eInvalidIncrement(); // increment cannot be zero\n\t\t\t}\n\t\t\tparts[ 2 ] = v;\n\t\t}\n\t} else {\n\t\tparts.push( 1 ); // default increment\n\t}\n\n\t/* Starting Index */\n\n\t// Process the starting index...\n\tv = parts[ 0 ];\n\n\t// Case: empty starting index\n\tif ( v.length === 0 ) {\n\t\t// If the increment is negative, we need to iterate from the last index...\n\t\tif ( parts[ 2 ] < 0 && len > 0 ) {\n\t\t\tparts[ 0 ] = len - 1;\n\t\t} else {\n\t\t\tparts[ 0 ] = 0; // default starting index (inclusive)\n\t\t}\n\t}\n\t// Case: use of the \"end\" keyword\n\telse if ( RE_END.test( v ) ) {\n\t\tv = resolveEnd( v, len, parts[ 2 ] < 0, strict );\n\t\tif ( v < 0 ) {\n\t\t\tif ( v === -2 ) {\n\t\t\t\treturn eOutOfBounds();\n\t\t\t}\n\t\t\treturn eInvalidSubsequence();\n\t\t}\n\t\tif ( parts[ 2 ] < 0 && v >= len ) {\n\t\t\tv -= 1; // clamp to the last index\n\t\t}\n\t\tparts[ 0 ] = v;\n\t}\n\t// Case: integer character sequence\n\telse if ( RE_INTEGER.test( v ) ) {\n\t\tv = parseInt( v, 10 );\n\n\t\t// Check whether we need to resolve the starting index relative to the last index...\n\t\tif ( v < 0 ) {\n\t\t\tv = len + v;\n\n\t\t\t// If the computed index exceeds the index bounds, clamp to the first index...\n\t\t\tif ( v < 0 ) {\n\t\t\t\tif ( strict ) {\n\t\t\t\t\treturn eOutOfBounds();\n\t\t\t\t}\n\t\t\t\tv = 0;\n\t\t\t}\n\t\t}\n\t\t// If the index exceeds the index bounds, clamp to the starting index...\n\t\telse if ( v >= len ) {\n\t\t\tif ( strict ) {\n\t\t\t\treturn eOutOfBounds();\n\t\t\t}\n\t\t\t// If the increment is negative, clamp to the last index (inclusive)...\n\t\t\tif ( parts[ 2 ] < 0 ) {\n\t\t\t\tv = len - 1;\n\t\t\t}\n\t\t\t// If the increment is positive, clamp to the \"index\" following the last index...\n\t\t\telse {\n\t\t\t\tv = len;\n\t\t\t}\n\t\t}\n\t\tparts[ 0 ] = v;\n\t}\n\t// Case: invalid/unsupported characters/operations\n\telse {\n\t\treturn eInvalidSubsequence();\n\t}\n\n\t/* Ending Index */\n\n\t// Processing the ending index...\n\tv = parts[ 1 ];\n\n\t// Case: empty ending index\n\tif ( v.length === 0 ) {\n\t\t// If the increment is negative, we need to iterate toward the first index...\n\t\tif ( parts[ 2 ] < 0 ) {\n\t\t\tparts[ 1 ] = null;\n\t\t} else {\n\t\t\tparts[ 1 ] = len; // default ending index (exclusive)\n\t\t}\n\t}\n\t// Case: use of the \"end\" keyword\n\telse if ( RE_END.test( v ) ) {\n\t\tv = resolveEnd( v, len, parts[ 2 ] < 0, strict );\n\t\tif ( v < 0 ) {\n\t\t\tif ( v === -2 ) {\n\t\t\t\treturn eOutOfBounds();\n\t\t\t}\n\t\t\treturn eInvalidSubsequence();\n\t\t}\n\t\tparts[ 1 ] = v;\n\t}\n\t// Case: integer character sequence\n\telse if ( RE_INTEGER.test( v ) ) {\n\t\tv = parseInt( v, 10 );\n\n\t\t// Check whether we need to resolve the starting index relative to the last index...\n\t\tif ( v < 0 ) {\n\t\t\tv = len + v;\n\n\t\t\t// Check whether the computed index exceeds the index bounds...\n\t\t\tif ( v < 0 ) {\n\t\t\t\t// If the increment is positive, clamp the ending index to the first index (exclusive)...\n\t\t\t\tif ( parts[ 2 ] > 0 ) {\n\t\t\t\t\tif ( strict ) {\n\t\t\t\t\t\treturn eOutOfBounds();\n\t\t\t\t\t}\n\t\t\t\t\tv = 0;\n\t\t\t\t} else {\n\t\t\t\t\t// If the increment is negative, the ending index should resolve to the first index (inclusive)...\n\t\t\t\t\tif ( strict && v < -1 ) {\n\t\t\t\t\t\treturn eOutOfBounds();\n\t\t\t\t\t}\n\t\t\t\t\tv = null;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// If the index exceeds the index bounds, clamp to the last \"index\" (exclusive)...\n\t\telse if ( v > len ) {\n\t\t\tif ( strict ) {\n\t\t\t\treturn eOutOfBounds();\n\t\t\t}\n\t\t\tv = len;\n\t\t}\n\t\tparts[ 1 ] = v;\n\t}\n\t// Case: invalid/unsupported characters/operations\n\telse {\n\t\treturn eInvalidSubsequence();\n\t}\n\n\t// Handle empty slice (note: this is at the end rather than at the beginning in order to ensure that `start` and `stop` are always validated)...\n\tif ( len === 0 ) {\n\t\treturn new Slice( 0, 0, parts[ 2 ] );\n\t}\n\n\treturn new Slice( parts[ 0 ], parts[ 1 ], parts[ 2 ] );\n}\n\n\n// EXPORTS //\n\nmodule.exports = seq2slice;\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* Convert a subsequence string to a Slice object.\n*\n* @module @stdlib/slice-base-seq2slice\n*\n* @example\n* var seq2slice = require( '@stdlib/slice-base-seq2slice' );\n*\n* var s = seq2slice( '0:10:1', 10, false );\n* // returns \n*\n* var v = s.start;\n* // returns 0\n*\n* v = s.stop;\n* // returns 10\n*\n* v = s.step;\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], + "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+DA,IA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AAOa,EAAO,CAAE,EAAGA,EAAO,CAAE,EAAGA,EAAO,CAAE,CAAE,CACtD,CAKAd,EAAO,QAAUU,ICldjB,IAAIO,EAAO,IAKX,OAAO,QAAUA", "names": ["require_re_end_minus", "__commonJSMin", "exports", "module", "RE_END_MINUS", "require_re_end_divide", "__commonJSMin", "exports", "module", "RE_END_DIVIDE", "require_resolve_end", "__commonJSMin", "exports", "module", "floor", "RE_END_MINUS", "RE_END_DIVIDE", "resolveEnd", "v", "len", "decrement", "strict", "tmp", "require_re_colon_sep", "__commonJSMin", "exports", "module", "RE_COLON_SEP", "require_re_integer", "__commonJSMin", "exports", "module", "RE_INTEGER", "require_re_end", "__commonJSMin", "exports", "module", "RE_END", "require_error_invalid_subsequence", "__commonJSMin", "exports", "module", "error", "require_error_out_of_bounds", "__commonJSMin", "exports", "module", "error", "require_error_invalid_increment", "__commonJSMin", "exports", "module", "error", "require_main", "__commonJSMin", "exports", "module", "Slice", "trim", "resolveEnd", "RE_COLON_SEP", "RE_INTEGER", "RE_END", "eInvalidSubsequence", "eOutOfBounds", "eInvalidIncrement", "seq2slice", "str", "len", "strict", "parts", "N", "v", "main"] } diff --git a/docs/repl.txt b/docs/repl.txt index 230ea05..9c85491 100644 --- a/docs/repl.txt +++ b/docs/repl.txt @@ -47,7 +47,7 @@ When the provided length is zero, the function always returns a slice object equivalent to '0:0:'. - The function returns an error object if provided in invalid subsequence + The function returns an error object if provided an invalid subsequence string. In strict mode, the function returns an error object if provided a @@ -59,11 +59,11 @@ A returned error object may have one of the following error codes: - - ERR_INVALID_SUBSEQUENCE: a subsequence string is invalid. - - ERR_INVALID_INCREMENT: a subsequence string must have a non-zero + - ERR_SLICE_INVALID_SUBSEQUENCE: a subsequence string is invalid. + - ERR_SLICE_INVALID_INCREMENT: a subsequence string must have a non-zero increment. - - ERR_OUT_OF_BOUNDS: a subsequence string resolves to a slice exceeding - index bounds. + - ERR_SLICE_OUT_OF_BOUNDS: a subsequence string resolves to a slice + exceeding index bounds. Parameters ---------- diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts index 793fe2c..bc7193b 100644 --- a/docs/types/index.d.ts +++ b/docs/types/index.d.ts @@ -29,7 +29,7 @@ interface ErrorObject { /** * Error code. */ - code: 'ERR_INVALID_SUBSEQUENCE' | 'ERR_INVALID_INCREMENT' | 'ERR_OUT_OF_BOUNDS'; + code: 'ERR_SLICE_INVALID_SUBSEQUENCE' | 'ERR_SLICE_INVALID_INCREMENT' | 'ERR_SLICE_OUT_OF_BOUNDS'; } /** @@ -68,7 +68,7 @@ type SliceResult = Slice | ErrorObject; * * - When `len` is zero, the function always returns a Slice object equivalent to `0:0:`. * -* - The function returns an error object if provided in invalid subsequence string. +* - The function returns an error object if provided an invalid subsequence string. * * - If `strict` is `true`, the function returns an error object if provided a subsequence string which exceeds index bounds. * diff --git a/lib/error_invalid_increment.js b/lib/error_invalid_increment.js index e342802..095295b 100644 --- a/lib/error_invalid_increment.js +++ b/lib/error_invalid_increment.js @@ -28,7 +28,7 @@ */ function error() { return { - 'code': 'ERR_INVALID_INCREMENT' + 'code': 'ERR_SLICE_INVALID_INCREMENT' }; } diff --git a/lib/error_invalid_subsequence.js b/lib/error_invalid_subsequence.js index e958e9f..b3b12e9 100644 --- a/lib/error_invalid_subsequence.js +++ b/lib/error_invalid_subsequence.js @@ -28,7 +28,7 @@ */ function error() { return { - 'code': 'ERR_INVALID_SUBSEQUENCE' + 'code': 'ERR_SLICE_INVALID_SUBSEQUENCE' }; } diff --git a/lib/error_out_of_bounds.js b/lib/error_out_of_bounds.js index 5d866d0..373cacb 100644 --- a/lib/error_out_of_bounds.js +++ b/lib/error_out_of_bounds.js @@ -28,7 +28,7 @@ */ function error() { return { - 'code': 'ERR_OUT_OF_BOUNDS' + 'code': 'ERR_SLICE_OUT_OF_BOUNDS' }; } diff --git a/lib/main.js b/lib/main.js index 4f6b50c..e06d4ac 100644 --- a/lib/main.js +++ b/lib/main.js @@ -64,7 +64,7 @@ var eInvalidIncrement = require( './error_invalid_increment.js' ); * * - When `len` is zero, the function always returns a Slice object equivalent to `0:0:`. * -* - The function returns an error object if provided in invalid subsequence string. +* - The function returns an error object if provided an invalid subsequence string. * * - If `strict` is `true`, the function returns an error object if provided a subsequence string which exceeds index bounds. * diff --git a/package.json b/package.json index e1e598a..279cf2b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@stdlib/slice-base-seq2slice", - "version": "0.0.0", + "version": "0.0.1", "description": "Convert a subsequence string to a Slice object.", "license": "Apache-2.0", "author": { diff --git a/test/test.js b/test/test.js index 97f5754..137f024 100644 --- a/test/test.js +++ b/test/test.js @@ -98,7 +98,7 @@ tape( 'the function returns an error object if provided a first argument which i ':end/1s' ]; expected = { - 'code': 'ERR_INVALID_SUBSEQUENCE' + 'code': 'ERR_SLICE_INVALID_SUBSEQUENCE' }; for ( i = 0; i < values.length; i++ ) { t.deepEqual( seq2slice( values[ i ], 10, false ), expected, 'returns expected value when provided ' + values[ i ] ); @@ -119,7 +119,7 @@ tape( 'the function returns an error object if provided a first argument which i ':end/0.5:' ]; expected = { - 'code': 'ERR_INVALID_SUBSEQUENCE' + 'code': 'ERR_SLICE_INVALID_SUBSEQUENCE' }; for ( i = 0; i < values.length; i++ ) { t.deepEqual( seq2slice( values[ i ], 10, false ), expected, 'returns expected value when provided ' + values[ i ] ); @@ -159,7 +159,7 @@ tape( 'the function returns an error object if provided a first argument which i ':end-20:5' ]; expected = { - 'code': 'ERR_OUT_OF_BOUNDS' + 'code': 'ERR_SLICE_OUT_OF_BOUNDS' }; for ( i = 0; i < values.length; i++ ) { t.deepEqual( seq2slice( values[ i ], 10, true ), expected, 'returns expected value when provided ' + values[ i ] ); @@ -182,7 +182,7 @@ tape( 'the function returns an error object if provided a first argument which i 'end:end:0' ]; expected = { - 'code': 'ERR_INVALID_INCREMENT' + 'code': 'ERR_SLICE_INVALID_INCREMENT' }; for ( i = 0; i < values.length; i++ ) { t.deepEqual( seq2slice( values[ i ], 10, false ), expected, 'returns expected value when provided ' + values[ i ] );