ut2
Version:
一个现代 JavaScript 实用工具库。[点击查看在线文档]。
29 lines (28 loc) • 579 B
TypeScript
/**
* 转换 `value` 为一个安全整数。
*
* @alias module:Util.toSafeInteger
* @since 1.0.0
* @param {*} value 要转换的值。
* @returns {number} 转换后的整数。
* @example
*
* toSafeInteger(3.2); // 3
*
* toSafeInteger('3.2'); // 3
*
* toSafeInteger(-0); // -0
*
* toSafeInteger('-0'); // -0
*
* toSafeInteger('0'); // 0
*
* toSafeInteger(NaN); // 0
*
* toSafeInteger(Infinity); // 9007199254740991
*
* toSafeInteger(-Infinity); // -9007199254740991
*
*/
declare function toSafeInteger(value: any): number;
export default toSafeInteger;