0

I've seen some time ago a video where a guy just selected whole text table in an internet browser, pasted it in the editor an than run some plugin/tool that automatically converted the text to actual objects array. I'm not sure what editor he was using (probably vim) or even what the language was, but I would love to have this now to create JS objects array, preferably in Visual Studio Code but I can't find it for any editor. I what to convert table like on this page to something like this:

var MACHINE_TYPES = [
    { name:"IMAGE_FILE_MACHINE_UNKNOWN", value:0x0, description:"The contents of this field are assumed to be applicable to any machine type"},
    { name:"IMAGE_FILE_MACHINE_I386 ", value:0x14c , description:"Intel 386 or later processors and compatible processors"},
];

by just simply pasting and specifying column names.

2 Answers2

1

I'm not aware on how to do that in Visual Studio Code, but a quick search gave me this HTML Table To JSON Converter. Quickly copied the HTML table from your microsoft link and uploaded it to that website returned the expected results:

[
 {
   "Constant": "IMAGE_FILE_MACHINE_UNKNOWN",
   "Value": 0,
   "Description": "The contents of this field are assumed to be applicable to any machine type"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_AM33",
   "Value": 13,
   "Description": "Matsushita AM33"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_AMD64",
   "Value": 8664,
   "Description": "x64"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_ARM",
   "Value": 10,
   "Description": "ARM little endian"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_ARM64",
   "Value": 64,
   "Description": "ARM64 little endian"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_ARMNT",
   "Value": 14,
   "Description": "ARM Thumb-2 little endian"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_EBC",
   "Value": 0e,
   "Description": "EFI byte code"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_I386",
   "Value": 14,
   "Description": "Intel 386 or later processors and compatible processors"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_IA64",
   "Value": 200,
   "Description": "Intel Itanium processor family"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_M32R",
   "Value": 9041,
   "Description": "Mitsubishi M32R little endian"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_MIPS16",
   "Value": 266,
   "Description": "MIPS16"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_MIPSFPU",
   "Value": 366,
   "Description": "MIPS with FPU"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_MIPSFPU16",
   "Value": 466,
   "Description": "MIPS16 with FPU"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_POWERPC",
   "Value": 10,
   "Description": "Power PC little endian"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_POWERPCFP",
   "Value": 11,
   "Description": "Power PC with floating point support"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_R4000",
   "Value": 166,
   "Description": "MIPS little endian"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_RISCV32",
   "Value": 5032,
   "Description": "RISC-V 32-bit address space"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_RISCV64",
   "Value": 5064,
   "Description": "RISC-V 64-bit address space"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_RISCV128",
   "Value": 5128,
   "Description": "RISC-V 128-bit address space"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_SH3",
   "Value": 12,
   "Description": "Hitachi SH3"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_SH3DSP",
   "Value": 13,
   "Description": "Hitachi SH3 DSP"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_SH4",
   "Value": 16,
   "Description": "Hitachi SH4"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_SH5",
   "Value": 18,
   "Description": "Hitachi SH5"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_THUMB",
   "Value": 12,
   "Description": "Thumb"
 },
 {
   "Constant": "IMAGE_FILE_MACHINE_WCEMIPSV2",
   "Value": 169,
   "Description": "MIPS little-endian WCE v2"
 }
]
Yassine Addi
  • 343
  • 2
  • 10
  • Turns out I to stupid to use this page :P How you did this? I pasted the link, clicked load button but it say there are 0 tables... – Paweł Audionysos Jan 28 '19 at 00:34
  • No problemo. use the chrome devtools to copy the whole table and paste the code into a `test.html` and it'll take care of the rest. Regarding the value fields, you can just use the resulting JSON object as a starting point, it's better anyway to update those instead of writing the whole thing.. ;) – Yassine Addi Jan 28 '19 at 00:42
  • I mean the guy was just coping plain text (no html source). This just pastes each cell with line break... I'm browsing extension there's got the be some that already do this. – Paweł Audionysos Jan 28 '19 at 00:49
0

I found Text Power Tools that allows replacing text through command pallete using regular expressions but it's quite problematic form more complex transformation so I used RegEx page using following formula for match:

`(.*)\s(.*)\s(.*)\s`

and for the replacement

{name:$1, value:$2, description:"$3"},\n