-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.mjs.map
1 lines (1 loc) · 6.73 KB
/
index.mjs.map
1
{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/error_out_of_bounds.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// MODULES //\n\nimport Slice from '@stdlib/slice-ctor';\nimport eOutOfBounds from './error_out_of_bounds.js';\n\n\n// MAIN //\n\n/**\n* Returns a normalized Slice object.\n*\n* @param {Slice} slice - input slice\n* @param {NonNegativeInteger} len - maximum number of elements allowed in a slice\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @returns {(Slice|ErrorObject)} slice object or an error object\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n*\n* var s = normalizeSlice( new Slice(), 10, false );\n* // returns <Slice>\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* import Slice from '@stdlib/slice-ctor';\n*\n* var s = normalizeSlice( new Slice( null, 20, 2 ), 10, false );\n* // returns <Slice>\n*\n* var v = s.start;\n* // returns 0\n*\n* v = s.stop;\n* // returns 10\n*\n* v = s.step;\n* // returns 2\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n*\n* var s = normalizeSlice( new Slice( -5, -1, 1 ), 10, false );\n* // returns <Slice>\n*\n* var v = s.start;\n* // returns 5\n*\n* v = s.stop;\n* // returns 9\n*\n* v = s.step;\n* // returns 1\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n*\n* var s = normalizeSlice( new Slice( -5, null, -1 ), 10, false );\n* // returns <Slice>\n*\n* var v = s.start;\n* // returns 5\n*\n* v = s.stop;\n* // returns null\n*\n* v = s.step;\n* // returns -1\n*/\nfunction normalizeSlice( slice, len, strict ) {\n\tvar start;\n\tvar stop;\n\tvar step;\n\n\tstart = slice.start;\n\tstop = slice.stop;\n\tstep = slice.step;\n\n\t// If necessary, set the default increment...\n\tif ( step === null ) {\n\t\tstep = 1;\n\t}\n\n\t// Case: start is not specified\n\tif ( start === null ) {\n\t\t// If the step is positive, we default to the first index...\n\t\tif ( step > 0 ) {\n\t\t\tstart = 0;\n\t\t}\n\t\t// If the step is negative, we default to the last index (inclusive)...\n\t\telse {\n\t\t\tstart = len - 1;\n\t\t}\n\t}\n\t// Case: start is negative and should be resolved relative to the last index\n\telse if ( start < 0 ) {\n\t\tstart = len + start;\n\n\t\t// Check whether start still exceeds the index bounds...\n\t\tif ( start < 0 ) {\n\t\t\tif ( strict ) {\n\t\t\t\treturn eOutOfBounds();\n\t\t\t}\n\t\t\t// Clamp to the first index (inclusive):\n\t\t\tstart = 0;\n\t\t}\n\t}\n\t// Case: start exceeds index bounds\n\telse if ( start >= len ) {\n\t\tif ( strict ) {\n\t\t\treturn eOutOfBounds();\n\t\t}\n\t\t// If the increment is negative, clamp to the last index (inclusive)...\n\t\tif ( step < 0 ) {\n\t\t\tstart = len - 1;\n\t\t}\n\t\t// If the increment is positive, clamp to the \"index\" following the last index...\n\t\telse {\n\t\t\tstart = len;\n\t\t}\n\t}\n\n\t// Case: stop is not specified\n\tif ( stop === null ) {\n\t\t// If the step is positive, we default to just beyond the last index, as the stopping index is exclusive...\n\t\tif ( step > 0 ) {\n\t\t\tstop = len;\n\t\t}\n\t\t// If the step is negative, we default to a sentinel value indicating that one should iterate through the first index when decrementing...\n\t\telse {\n\t\t\tstop = null;\n\t\t}\n\t}\n\t// Case: stop is negative and should be resolved relative to the last index\n\telse if ( stop < 0 ) {\n\t\tstop = len + stop;\n\n\t\t// Check whether stop still exceeds the index bounds...\n\t\tif ( stop < 0 ) {\n\t\t\t// If the step is positive, we should clamp to the first index, as Slice(x,0,step) is an empty slice regardless of `x`...\n\t\t\tif ( step > 0 ) {\n\t\t\t\tif ( strict ) {\n\t\t\t\t\treturn eOutOfBounds();\n\t\t\t\t}\n\t\t\t\tstop = 0;\n\t\t\t}\n\t\t\t// If the step is negative, we default to just beyond the first index (using a sentinel value), as the stopping index is exclusive, thus indicating to iterate through the first index when decrementing...\n\t\t\telse {\n\t\t\t\tif ( strict && stop < -1 ) {\n\t\t\t\t\treturn eOutOfBounds();\n\t\t\t\t}\n\t\t\t\tstop = null;\n\t\t\t}\n\t\t}\n\t}\n\t// Case: stop exceeds index bounds\n\telse if ( stop > len ) {\n\t\tif ( strict ) {\n\t\t\treturn eOutOfBounds();\n\t\t}\n\t\t// Clamp to just beyond the last index, as the stopping index is exclusive:\n\t\tstop = len;\n\t}\n\n\t// Return a normalized slice:\n\treturn new Slice( start, stop, step );\n}\n\n\n// EXPORTS //\n\nexport default normalizeSlice;\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 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\nexport default error;\n"],"names":["normalizeSlice","slice","len","strict","start","stop","step","code","Slice"],"mappings":";;qFAgGA,SAASA,EAAgBC,EAAOC,EAAKC,GACpC,IAAIC,EACAC,EACAC,EAYJ,GAVAF,EAAQH,EAAMG,MACdC,EAAOJ,EAAMI,KAIC,QAHdC,EAAOL,EAAMK,QAIZA,EAAO,GAIO,OAAVF,EAGHA,EADIE,EAAO,EACH,EAIAJ,EAAM,OAIX,GAAKE,EAAQ,GAIjB,IAHAA,EAAQF,EAAME,GAGD,EAAI,CAChB,GAAKD,EACJ,MCnGI,CACNI,KAAQ,2BDqGPH,EAAQ,CACR,OAGG,GAAKA,GAASF,EAAM,CACxB,GAAKC,EACJ,MC5GK,CACNI,KAAQ,2BD+GPH,EADIE,EAAO,EACHJ,EAAM,EAINA,CAET,CAGD,GAAc,OAATG,EAGHA,EADIC,EAAO,EACJJ,EAIA,UAIJ,GAAKG,EAAO,GAIhB,IAHAA,EAAOH,EAAMG,GAGD,EAEX,GAAKC,EAAO,EAAI,CACf,GAAKH,EACJ,MC5IG,CACNI,KAAQ,2BD6INF,EAAO,CACP,KAEI,CACJ,GAAKF,GAAUE,GAAQ,EACtB,MCnJG,CACNE,KAAQ,2BDoJNF,EAAO,IACP,OAIE,GAAKA,EAAOH,EAAM,CACtB,GAAKC,EACJ,MC5JK,CACNI,KAAQ,2BD8JRF,EAAOH,CACP,CAGD,OAAO,IAAIM,EAAOJ,EAAOC,EAAMC,EAChC"}