cyberchef/src/core/operations/FromPunycode.mjs
GCHQDeveloper581 1fdd2ecf20
Node version update from 22 to 24 (#2347)
Changes mostly authored-by: Leon Zandman <leon@wirwar.com>
Cherry pick and minor additions by GCHQDeveloper581 <63102987+GCHQDeveloper581@users.noreply.github.com>
2026-04-28 13:18:02 +01:00

54 lines
1.3 KiB
JavaScript

/**
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2016
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import punycode from "punycode.js";
/**
* From Punycode operation
*/
class FromPunycode extends Operation {
/**
* FromPunycode constructor
*/
constructor() {
super();
this.name = "From Punycode";
this.module = "Encodings";
this.description = "Punycode is a way to represent Unicode with the limited character subset of ASCII supported by the Domain Name System.<br><br>e.g. <code>mnchen-3ya</code> decodes to <code>m\xfcnchen</code>";
this.infoURL = "https://wikipedia.org/wiki/Punycode";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Internationalised domain name",
"type": "boolean",
"value": false
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const idn = args[0];
if (idn) {
return punycode.toUnicode(input);
} else {
return punycode.decode(input);
}
}
}
export default FromPunycode;