-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.mjs.map
1 lines (1 loc) · 3.94 KB
/
index.mjs.map
1
{"version":3,"file":"index.mjs","sources":["../lib/main.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 ceil from '@stdlib/math-base-special-ceil';\n\n\n// MAIN //\n\n/**\n* Returns the number of elements in a normalized slice.\n*\n* @param {Slice} slice - normalized Slice object\n* @returns {NonNegativeInteger} number of elements\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import normalizeSlice from '@stdlib/slice-base-normalize-slice';\n*\n* var s = new Slice( 2, null, 1 );\n* // returns <Slice>\n*\n* var v = sliceLength( normalizeSlice( s, 10, false ) );\n* // returns 8\n*\n* v = sliceLength( normalizeSlice( s, 11, false ) );\n* // returns 9\n*\n* v = sliceLength( normalizeSlice( s, 5, false ) );\n* // returns 3\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import normalizeSlice from '@stdlib/slice-base-normalize-slice';\n*\n* var s = new Slice( 2, null, 2 );\n* // returns <Slice>\n*\n* var v = sliceLength( normalizeSlice( s, 10, false ) );\n* // returns 4\n*\n* v = sliceLength( normalizeSlice( s, 11, false ) );\n* // returns 5\n*\n* v = sliceLength( normalizeSlice( s, 5, false ) );\n* // returns 2\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import normalizeSlice from '@stdlib/slice-base-normalize-slice';\n*\n* var s = new Slice( -1, null, -2 );\n*\n* var v = sliceLength( normalizeSlice( s, 10, false ) );\n* // returns 5\n*\n* v = sliceLength( normalizeSlice( s, 11, false ) );\n* // returns 6\n*\n* v = sliceLength( normalizeSlice( s, 5, false ) );\n* // returns 3\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import normalizeSlice from '@stdlib/slice-base-normalize-slice';\n*\n* var s = new Slice( 3, 5, -1 );\n*\n* var v = sliceLength( normalizeSlice( s, 10, false ) );\n* // returns 0\n*\n* v = sliceLength( normalizeSlice( s, 11, false ) );\n* // returns 0\n*\n* v = sliceLength( normalizeSlice( s, 5, false ) );\n* // returns 0\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import normalizeSlice from '@stdlib/slice-base-normalize-slice';\n*\n* var s = new Slice( 5, 3, 1 );\n*\n* var v = sliceLength( normalizeSlice( s, 10, false ) );\n* // returns 0\n*\n* v = sliceLength( normalizeSlice( s, 11, false ) );\n* // returns 0\n*\n* v = sliceLength( normalizeSlice( s, 5, false ) );\n* // returns 0\n*/\nfunction sliceLength( slice ) {\n\tvar inc;\n\tvar x1;\n\tvar x2;\n\n\tx1 = slice.start;\n\tx2 = slice.stop;\n\tinc = slice.step;\n\n\t// For a normalized slice, stop should only be `null` when the increment is negative...\n\tif ( x2 === null ) {\n\t\tx2 = -1; // set to -1 to ensure that the first element is included\n\t}\n\tif (\n\t\t// If the increment is positive, the slice is empty whenever the starting index is greater than or equal to the stopping index:\n\t\t( inc > 0 && x1 >= x2 ) ||\n\n\t\t// If the increment is negative, the slice is empty whenever the starting index is less than or equal to the stopping index:\n\t\t( inc < 0 && x1 <= x2 )\n\t) {\n\t\treturn 0;\n\t}\n\treturn ceil( ( x2 - x1 ) / inc );\n}\n\n\n// EXPORTS //\n\nexport default sliceLength;\n"],"names":["sliceLength","slice","inc","x1","x2","start","stop","step","ceil"],"mappings":";;iGA8GA,SAASA,EAAaC,GACrB,IAAIC,EACAC,EACAC,EAUJ,OARAD,EAAKF,EAAMI,MAKC,QAJZD,EAAKH,EAAMK,QAKVF,GAAM,IAJPF,EAAMD,EAAMM,MAQH,GAAKJ,GAAMC,GAGjBF,EAAM,GAAKC,GAAMC,EAEZ,EAEDI,GAAQJ,EAAKD,GAAOD,EAC5B"}