UNPKG

slp-enforcer

Version:

Finds violations of the Melee Controller Ruleset by inspecting SLP files

38 lines (37 loc) 1.21 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const map_1 = __importDefault(require("lodash/map")); function toHalfwidth(str) { // Converts a fullwidth character to halfwidth const convertChar = (charCode) => { /** * Standard full width encodings * https://en.wikipedia.org/wiki/Halfwidth_and_Fullwidth_Forms_(Unicode_block) */ if (charCode > 0xff00 && charCode < 0xff5f) { return 0x0020 + (charCode - 0xff00); } // space: if (charCode === 0x3000) { return 0x0020; } /** * Exceptions found in Melee/Japanese keyboards */ // single quote: ' if (charCode === 0x2019) { return 0x0027; } // double quote: " if (charCode === 0x201d) { return 0x0022; } return charCode; }; const ret = map_1.default(str, (char) => convertChar(char.charCodeAt(0))); return String.fromCharCode(...ret); } exports.toHalfwidth = toHalfwidth;