File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,27 +6,25 @@ export const DEFAULT_PAGE_WEIGHT = -1;
66/**
77 * Normalizes a page weight value to a finite number, or falls back to default.
88 *
9- * @param {unknown } weight
9+ * @param {number|string } weight
1010 * @returns {number }
1111 */
1212export const normalizePageWeight = weight => {
13- if ( typeof weight === 'number' && Number . isFinite ( weight ) ) {
14- return weight ;
13+ let candidate = NaN ;
14+
15+ if ( typeof weight === 'number' ) {
16+ candidate = weight ;
1517 }
1618
1719 if ( typeof weight === 'string' ) {
1820 const trimmedWeight = weight . trim ( ) ;
1921
20- if ( trimmedWeight . length > 0 ) {
21- const parsedWeight = Number ( trimmedWeight ) ;
22-
23- if ( Number . isFinite ( parsedWeight ) ) {
24- return parsedWeight ;
25- }
22+ if ( trimmedWeight !== '' ) {
23+ candidate = Number ( trimmedWeight ) ;
2624 }
2725 }
2826
29- return DEFAULT_PAGE_WEIGHT ;
27+ return Number . isFinite ( candidate ) ? candidate : DEFAULT_PAGE_WEIGHT ;
3028} ;
3129
3230/**
@@ -43,7 +41,7 @@ export const compareSidebarPageWeight = (a, b) => {
4341 const aHasWeight = a . weight !== DEFAULT_PAGE_WEIGHT ;
4442 const bHasWeight = b . weight !== DEFAULT_PAGE_WEIGHT ;
4543
46- if ( aHasWeight && bHasWeight && a . weight !== b . weight ) {
44+ if ( aHasWeight && bHasWeight ) {
4745 return a . weight - b . weight ;
4846 }
4947
You can’t perform that action at this time.
0 commit comments