dec

Converts decimal entities

Created by: hackvertor
Installed 1 times

Category: Convert

Created on: Thursday, October 3, 2024 at 6:54:03 PM

Updated on: Friday, December 20, 2024 at 8:08:04 PM

This is a built in tag
Tag arguments
[]
Code
class dec {
  encode(input) {
    return input.split('').map(chr => '&#'+chr.codePointAt()+';').join('');
  }

  decode(input) {
    return input.replaceAll(/&#\d+;/gi, c => String.fromCodePoint(parseInt(c.replaceAll(/[&#;]/g,''))));
  }

  matches(input) {
    return /^(?:&#\d+;)+/.exec(input);
  }
}