mirror of
https://github.com/gchq/CyberChef.git
synced 2026-03-26 16:51:26 -07:00
use OperationError to handle errors and also normalise input handling in operation To IEEEBinary
This commit is contained in:
parent
5e427e8531
commit
b087317acd
1 changed files with 15 additions and 4 deletions
|
|
@ -4,6 +4,7 @@
|
|||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import Operation from "../Operation.mjs";
|
||||
import { ToIEEE754Float64 } from "../lib/IEEEBinary.mjs";
|
||||
|
||||
|
|
@ -34,13 +35,23 @@ class ToIEEEBinary extends Operation {
|
|||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
if (!input || input.trim().length === 0) {
|
||||
return "";
|
||||
}
|
||||
run(input, args) {
|
||||
if (input === null || input === undefined)
|
||||
return "";
|
||||
|
||||
input = String(input);
|
||||
|
||||
if (input.trim().length === 0)
|
||||
return "";
|
||||
|
||||
try {
|
||||
return ToIEEE754Float64(input);
|
||||
} catch (err) {
|
||||
throw new OperationError(err.message);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ToIEEEBinary;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue