8889841cesm/index.js000066600000005067150544710420007013 0ustar00import Long from "@xtuc/long"; import parseHexFloat from "@webassemblyjs/floating-point-hex-parser"; import { CompileError } from "@webassemblyjs/helper-api-error"; export function parse32F(sourceString) { if (isHexLiteral(sourceString)) { return parseHexFloat(sourceString); } if (isInfLiteral(sourceString)) { return sourceString[0] === "-" ? -1 : 1; } if (isNanLiteral(sourceString)) { return (sourceString[0] === "-" ? -1 : 1) * (sourceString.includes(":") ? parseInt(sourceString.substring(sourceString.indexOf(":") + 1), 16) : 0x400000); } return parseFloat(sourceString); } export function parse64F(sourceString) { if (isHexLiteral(sourceString)) { return parseHexFloat(sourceString); } if (isInfLiteral(sourceString)) { return sourceString[0] === "-" ? -1 : 1; } if (isNanLiteral(sourceString)) { return (sourceString[0] === "-" ? -1 : 1) * (sourceString.includes(":") ? parseInt(sourceString.substring(sourceString.indexOf(":") + 1), 16) : 0x8000000000000); } if (isHexLiteral(sourceString)) { return parseHexFloat(sourceString); } return parseFloat(sourceString); } export function parse32I(sourceString) { var value = 0; if (isHexLiteral(sourceString)) { value = ~~parseInt(sourceString, 16); } else if (isDecimalExponentLiteral(sourceString)) { throw new Error("This number literal format is yet to be implemented."); } else { value = parseInt(sourceString, 10); } return value; } export function parseU32(sourceString) { var value = parse32I(sourceString); if (value < 0) { throw new CompileError("Illegal value for u32: " + sourceString); } return value; } export function parse64I(sourceString) { var long; if (isHexLiteral(sourceString)) { long = Long.fromString(sourceString, false, 16); } else if (isDecimalExponentLiteral(sourceString)) { throw new Error("This number literal format is yet to be implemented."); } else { long = Long.fromString(sourceString); } return { high: long.high, low: long.low }; } var NAN_WORD = /^\+?-?nan/; var INF_WORD = /^\+?-?inf/; export function isInfLiteral(sourceString) { return INF_WORD.test(sourceString.toLowerCase()); } export function isNanLiteral(sourceString) { return NAN_WORD.test(sourceString.toLowerCase()); } function isDecimalExponentLiteral(sourceString) { return !isHexLiteral(sourceString) && sourceString.toUpperCase().includes("E"); } function isHexLiteral(sourceString) { return sourceString.substring(0, 2).toUpperCase() === "0X" || sourceString.substring(0, 3).toUpperCase() === "-0X"; }src/index.js000066600000005503150544710420007011 0ustar00// @flow import Long from "@xtuc/long"; import parseHexFloat from "@webassemblyjs/floating-point-hex-parser"; import { CompileError } from "@webassemblyjs/helper-api-error"; export function parse32F(sourceString: string): number { if (isHexLiteral(sourceString)) { return parseHexFloat(sourceString); } if (isInfLiteral(sourceString)) { return sourceString[0] === "-" ? -1 : 1; } if (isNanLiteral(sourceString)) { return ( (sourceString[0] === "-" ? -1 : 1) * (sourceString.includes(":") ? parseInt(sourceString.substring(sourceString.indexOf(":") + 1), 16) : 0x400000) ); } return parseFloat(sourceString); } export function parse64F(sourceString: string): number { if (isHexLiteral(sourceString)) { return parseHexFloat(sourceString); } if (isInfLiteral(sourceString)) { return sourceString[0] === "-" ? -1 : 1; } if (isNanLiteral(sourceString)) { return ( (sourceString[0] === "-" ? -1 : 1) * (sourceString.includes(":") ? parseInt(sourceString.substring(sourceString.indexOf(":") + 1), 16) : 0x8000000000000) ); } if (isHexLiteral(sourceString)) { return parseHexFloat(sourceString); } return parseFloat(sourceString); } export function parse32I(sourceString: string): number { let value = 0; if (isHexLiteral(sourceString)) { value = ~~parseInt(sourceString, 16); } else if (isDecimalExponentLiteral(sourceString)) { throw new Error("This number literal format is yet to be implemented."); } else { value = parseInt(sourceString, 10); } return value; } export function parseU32(sourceString: string): number { const value = parse32I(sourceString); if (value < 0) { throw new CompileError("Illegal value for u32: " + sourceString); } return value; } export function parse64I(sourceString: string): LongNumber { let long: Long; if (isHexLiteral(sourceString)) { long = Long.fromString(sourceString, false, 16); } else if (isDecimalExponentLiteral(sourceString)) { throw new Error("This number literal format is yet to be implemented."); } else { long = Long.fromString(sourceString); } return { high: long.high, low: long.low }; } const NAN_WORD = /^\+?-?nan/; const INF_WORD = /^\+?-?inf/; export function isInfLiteral(sourceString: string): boolean { return INF_WORD.test(sourceString.toLowerCase()); } export function isNanLiteral(sourceString: string): boolean { return NAN_WORD.test(sourceString.toLowerCase()); } function isDecimalExponentLiteral(sourceString: string): boolean { return ( !isHexLiteral(sourceString) && sourceString.toUpperCase().includes("E") ); } function isHexLiteral(sourceString: string): boolean { return ( sourceString.substring(0, 2).toUpperCase() === "0X" || sourceString.substring(0, 3).toUpperCase() === "-0X" ); } lib/index.js000066600000006107150544710420006771 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parse32F = parse32F; exports.parse64F = parse64F; exports.parse32I = parse32I; exports.parseU32 = parseU32; exports.parse64I = parse64I; exports.isInfLiteral = isInfLiteral; exports.isNanLiteral = isNanLiteral; var _long = _interopRequireDefault(require("@xtuc/long")); var _floatingPointHexParser = _interopRequireDefault(require("@webassemblyjs/floating-point-hex-parser")); var _helperApiError = require("@webassemblyjs/helper-api-error"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function parse32F(sourceString) { if (isHexLiteral(sourceString)) { return (0, _floatingPointHexParser.default)(sourceString); } if (isInfLiteral(sourceString)) { return sourceString[0] === "-" ? -1 : 1; } if (isNanLiteral(sourceString)) { return (sourceString[0] === "-" ? -1 : 1) * (sourceString.includes(":") ? parseInt(sourceString.substring(sourceString.indexOf(":") + 1), 16) : 0x400000); } return parseFloat(sourceString); } function parse64F(sourceString) { if (isHexLiteral(sourceString)) { return (0, _floatingPointHexParser.default)(sourceString); } if (isInfLiteral(sourceString)) { return sourceString[0] === "-" ? -1 : 1; } if (isNanLiteral(sourceString)) { return (sourceString[0] === "-" ? -1 : 1) * (sourceString.includes(":") ? parseInt(sourceString.substring(sourceString.indexOf(":") + 1), 16) : 0x8000000000000); } if (isHexLiteral(sourceString)) { return (0, _floatingPointHexParser.default)(sourceString); } return parseFloat(sourceString); } function parse32I(sourceString) { var value = 0; if (isHexLiteral(sourceString)) { value = ~~parseInt(sourceString, 16); } else if (isDecimalExponentLiteral(sourceString)) { throw new Error("This number literal format is yet to be implemented."); } else { value = parseInt(sourceString, 10); } return value; } function parseU32(sourceString) { var value = parse32I(sourceString); if (value < 0) { throw new _helperApiError.CompileError("Illegal value for u32: " + sourceString); } return value; } function parse64I(sourceString) { var long; if (isHexLiteral(sourceString)) { long = _long.default.fromString(sourceString, false, 16); } else if (isDecimalExponentLiteral(sourceString)) { throw new Error("This number literal format is yet to be implemented."); } else { long = _long.default.fromString(sourceString); } return { high: long.high, low: long.low }; } var NAN_WORD = /^\+?-?nan/; var INF_WORD = /^\+?-?inf/; function isInfLiteral(sourceString) { return INF_WORD.test(sourceString.toLowerCase()); } function isNanLiteral(sourceString) { return NAN_WORD.test(sourceString.toLowerCase()); } function isDecimalExponentLiteral(sourceString) { return !isHexLiteral(sourceString) && sourceString.toUpperCase().includes("E"); } function isHexLiteral(sourceString) { return sourceString.substring(0, 2).toUpperCase() === "0X" || sourceString.substring(0, 3).toUpperCase() === "-0X"; }LICENSE000066600000002100150544710420005550 0ustar00MIT License Copyright (c) 2018 Sven Sauleau Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package.json000066600000001215150544710420007037 0ustar00{ "name": "@webassemblyjs/helper-numbers", "version": "1.11.1", "description": "Number parsing utility", "main": "lib/index.js", "module": "esm/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "https://github.com/xtuc/webassemblyjs.git" }, "publishConfig": { "access": "public" }, "dependencies": { "@webassemblyjs/floating-point-hex-parser": "1.11.1", "@webassemblyjs/helper-api-error": "1.11.1", "@xtuc/long": "4.2.2" }, "author": "Sven Sauleau", "license": "MIT", "gitHead": "3f07e2db2031afe0ce686630418c542938c1674b" }