2023-01-09 19:02:19 -05:00
|
|
|
import {ExpressionData} from "./data";
|
2023-01-06 15:54:31 -08:00
|
|
|
|
|
|
|
|
export class idxHelper {
|
|
|
|
|
public readonly str: string | undefined;
|
|
|
|
|
public readonly int: number | undefined;
|
|
|
|
|
|
|
|
|
|
constructor(public readonly star: boolean, idx: ExpressionData | undefined) {
|
2023-03-16 18:08:51 -04:00
|
|
|
if (!idx) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-01-06 15:54:31 -08:00
|
|
|
if (!star) {
|
2023-03-16 18:08:51 -04:00
|
|
|
if (idx.primitive) {
|
|
|
|
|
this.str = idx.coerceString();
|
2023-01-06 15:54:31 -08:00
|
|
|
}
|
|
|
|
|
|
2023-03-16 18:08:51 -04:00
|
|
|
let f = idx.number();
|
2023-01-06 15:54:31 -08:00
|
|
|
if (!isNaN(f) && isFinite(f) && f >= 0) {
|
|
|
|
|
f = Math.floor(f);
|
|
|
|
|
this.int = f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|