9 lines
383 B
JavaScript
9 lines
383 B
JavaScript
/** 商品接口使用有符号 32 位正整数;在拼接后端路径之前拒绝数组、精度丢失和超限编号。 */
|
|
export function productId(value) {
|
|
if (typeof value !== "string" && typeof value !== "number") return null;
|
|
const text = String(value);
|
|
if (!/^[1-9]\d{0,9}$/.test(text)) return null;
|
|
const id = Number(text);
|
|
return id <= 2147483647 ? id : null;
|
|
}
|