Open obliqueRotationMethod opened 1 year ago
same issue.
ChatGPT helps:
import { inferType as originalInferType, JSONValueType, JSONIntType, JSONStringType } from '@jsonhero/json-infer-types';
export function inferType(value: unknown): JSONValueType {
const result: JSONValueType = originalInferType(value) as JSONValueType;
// check
if (typeof value === 'number') {
// if result is JSONStringType and format is datetime,change to JSONIntType
if (result.name === 'string' && 'format' in result && result.format?.name === 'datetime') {
return { name: 'int', value } as JSONIntType;
}
// return int directly
return { name: 'int', value } as JSONIntType;
}
// another check
if (result.name === 'string') {
const stringValue = result.value as string;
// if string looks like number,and should not as datetime
if (/^\d+$/.test(stringValue) && result.format?.name === 'datetime') {
return { name: 'int', value: parseInt(stringValue, 10) } as JSONIntType;
}
}
return result;
}
Hi,
running locally, I POST an pretty big JSON to the API. Some of my Strings in the JSON have Number-Characters only (userIDs). When opening the link, console is showing a lot of 'RangeError: invalid ISO 8601 string: 12345' - warnings/ errors. It takes up to one minute to open the link, npm service is running on 100% CPU usage
On the site, I see that the program interprets my Number-Strings as Date-Objects (string/datetime/rfc3339). Example: {"lastModifiedBy": "12345678"}
My actual date strings in there are ISO 8601-formated. Maybe a workaround could be to add a parameter to state the date format. To let the backend know which Strings to parse as dates and leave the rest as normal text?