Skip to content

Commit

Permalink
Fixed the binding option "addArrayIndexPadding" not working when set …
Browse files Browse the repository at this point in the history
…to true.
  • Loading branch information
William Troup committed Aug 31, 2024
1 parent c7f4fd2 commit 354b932
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions dist/jsontree.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ var Arr;
e.getIndex = t;
function n(e, t, n) {
let o = t.toString();
if (!e.addArrayIndexPadding) {
if (e.addArrayIndexPadding) {
o = Str.padNumber(parseInt(o), n.toString().length);
}
if (e.showArrayIndexBrackets) {
Expand All @@ -781,7 +781,7 @@ var Arr;
}
e.getIndexName = n;
function o(e) {
return parseInt(e.replace("[", "").replace("]", ""));
return parseInt(e.replace(/^\D+/g, ""));
}
e.getIndexFromBrackets = o;
function l(e, t, n) {
Expand Down
2 changes: 1 addition & 1 deletion dist/jsontree.esm.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/jsontree.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ var Arr;
e.getIndex = t;
function n(e, t, n) {
let o = t.toString();
if (!e.addArrayIndexPadding) {
if (e.addArrayIndexPadding) {
o = Str.padNumber(parseInt(o), n.toString().length);
}
if (e.showArrayIndexBrackets) {
Expand All @@ -783,7 +783,7 @@ var Arr;
}
e.getIndexName = n;
function o(e) {
return parseInt(e.replace("[", "").replace("]", ""));
return parseInt(e.replace(/^\D+/g, ""));
}
e.getIndexFromBrackets = o;
function l(e, t, n) {
Expand Down
2 changes: 1 addition & 1 deletion dist/jsontree.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jsontree.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/ts/data/arr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export namespace Arr {
export function getIndexName( bindingOptions: BindingOptions, index: number, largestValue: number ) : string {
let result: string = index.toString();

if ( !bindingOptions.addArrayIndexPadding ) {
if ( bindingOptions.addArrayIndexPadding ) {
result = Str.padNumber( parseInt( result ), largestValue.toString().length );
}

Expand All @@ -36,7 +36,7 @@ export namespace Arr {
}

export function getIndexFromBrackets( propertyName: string ) : number {
return parseInt( propertyName.replace( "[", Char.empty ).replace( "]", Char.empty ) );
return parseInt( propertyName.replace( /^\D+/g, Char.empty ) );
}

export function moveIndex( arrayData: any[], oldIndex: number, newIndex: number ) : void {
Expand Down
1 change: 1 addition & 0 deletions test/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function bindingOptions( showValueColors = true, allowValueToolTips = true ) {
showOpenedObjectArrayBorders: true,
showPropertyNameQuotes: false,
showPropertyNameAndIndexColors: true,
addArrayIndexPadding: false,
valueToolTips: allowValueToolTips ? {
"value1": "This is a boolean tooltip for Value 1",
"value5\\1": "This is a string tooltip for Value 1 > Array Index 1",
Expand Down

0 comments on commit 354b932

Please sign in to comment.