1.0.26 • Published 3 years ago

lotto-parser v1.0.26

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

lotto-parser

lotto-parser is a compiler for list lotto to object JSON

Features

  • Easy-to-use compiler
  • Handles all modern JS features
  • Bundles commonjs and es module formats
  • Supports complicated peer-dependencies
  • Supports Typescript

Demo

link to demo https://codesandbox.io/s/peaceful-khayyam-lsvctm

Usage/Examples

import { lottoCompiler } from "lotto-parser";

import { useState } from "react";

function App() {
  const [lottoBill, setLottoBill] = useState(`1 30*30
123 100*100
12 20*20
21 20*20
3^ 20*20
^4 20*20
%7 50*50
8% 50*50
567 100*100
^89 100*100
1^2 100*100
3^4 40*40
56^ 40*40
123# 100*100*100
`);

  return (
    <>
      <textarea
        value={lottoBill}
        onChange={(event) => setLottoBill(event.target.value)}
        style={{ width: "50%", height: "200px" }}
      />
      <br />
      <button
        onClick={() => {
          if (lottoBill) {
            try {
              let test = lottoCompiler(lottoBill);
              console.log(test);
            } catch (err) {
              console.log("err", err);
            }
          }
        }}
      >
        confirm
      </button>
    </>
  );
}

export default App;

Condition

เงื่อนไขการเขียนบิลความหมาย
12 100*100ซื้อ 12 บน 100 บาท ล่าง 100 บาท
21 100*10ซื้อ 21 บน 100 บาท ล่าง 100 บาท
^3 100*100ซื้อ 3 รูดหน้า บน 100 บาท ล่าง 100 บาท
4^ 100*100ซื้อ 4 รูดหลัง บน 100 บาท ล่าง 100 บาท
1% 100*100ซื้อ 1 แบบ 19 ประตู บน 100 บาท ล่าง 100 บาท
%1 100*100ซื้อ 1 แบบ 19 ประตู บน 100 บาท ล่าง 100 บาท (%อยู่ก่อนหรือหลังก็ได้)
123 100*100ซื้อ 123 บน 100 บาท โต๊ด 100 บาท
^23 100*100ซื้อ 23 รูดหลักแรก บน 100 บาท โต๊ด 100 บาท
2^3 100*100ซื้อ 23 รูดหลักสอง บน 100 บาท โต๊ด 100 บาท
23^ 100*100ซื้อ 23 รูดหลักสาม บน 100 บาท โต๊ด 100 บาท
12 100*0ซื้อ 12 บน 100 บาท ไม่ซื้อล่าง
23 0*100ซื้อ 23 ล่าง 100 บาท ไม่ซื้อบน
123 100*0ซื้อ 123 บน 100 บาท ไม่ซื้อโต๊ด
456 100*0ซื้อ 456 โต๊ด 100 บาท ไม่ซื้อบน
23^ 100*0ซื้อ 23 รูดหลักสาม บน 100 บาท ไม่ซื้อโต๊ด
1 100*100ซื้อเลข 1 วิ่ง 100 บาท ล่าง 100 บาท
123 0*0*100ซื้อเลข 123 โต๊ด 100 บาท (ใส่ *ตัวที่ 3 มาจะเป็นโต๊ด ถ้าไม่ใส่ tod_price จะเป็น undefined )
123 100*100*100ซื้อเลข 123 บน 100 ล่าง 100 โต๊ด 100 บาท
123# 100*100*100ซื้อเลข 123 แบบหกกลับ บน 100 ล่าง 100 โต๊ด 100

Response

จะ response object ออกมา มี type ดังนี้

keytypedescription
typenumberใช้เพื่อบอกประเภทของหวยถ้า 1 จะเป็นเลขวิ่ง 2 จะเป็นเลขสองตัว 3 จะเป็นเลข 3 ตัว
lottostringหวยที่ซื้อ
front_pricenumberราคาที่ซื้อเลขบน ถ้าส่งมาเป็น 0 แสดงว่าไม่ได้ซื้อ
back_pricenumberราคาที่ซื้อเลขล่าง แต่ถ้า type เป็น 3 จะเป็นการซื้อโต๊ด ถ้าส่งมาเป็น 0 แสดงว่าไม่ได้ซื้อ

example 1

12 100*100
[
   {
      "type": 2,
      "lotto": "12",
      "front_price": 100,
      "back_price": 100,
      "tod_price": undefined
   }
]

example 2

123 100*100
[
    {
      "type": 3,
      "lotto": "123",
      "front_price": 100,
      "back_price": 100,
      "tod_price": undefined
   }
]

example 3

^3 100*100
[
    {
        "type": 2,
        "lotto": "03",
        "front_price": 100,
        "back_price": 100,
        "tod_price": undefined
    },
    {
        "type": 2,
        "lotto": "13",
        "front_price": 100,
        "back_price": 100,
        "tod_price": undefined
    },
    {
        "type": 2,
        "lotto": "23",
        "front_price": 100,
        "back_price": 100,
        "tod_price": undefined
    },
    {
        "type": 2,
        "lotto": "33",
        "front_price": 100,
        "back_price": 100,
        "tod_price": undefined
    },
    {
        "type": 2,
        "lotto": "43",
        "front_price": 100,
        "back_price": 100,
        "tod_price": undefined
    },
    {
        "type": 2,
        "lotto": "53",
        "front_price": 100,
        "back_price": 100,
        "tod_price": undefined
    },
    {
        "type": 2,
        "lotto": "63",
        "front_price": 100,
        "back_price": 100,
        "tod_price": undefined
    },
    {
        "type": 2,
        "lotto": "73",
        "front_price": 100,
        "back_price": 100,
        "tod_price": undefined
    },
    {
        "type": 2,
        "lotto": "83",
        "front_price": 100,
        "back_price": 100,
        "tod_price": undefined
    },
    {
        "type": 2,
        "lotto": "93",
        "front_price": 100,
        "back_price": 100,
        "tod_price": undefined
    }
]

example 3

123# 100*100*100
[
    {
        "type": 3,
        "lotto": "123",
        "front_price": 100,
        "back_price": 100,
        "tod_price": 100
    },
    {
        "type": 3,
        "lotto": "132",
        "front_price": 100,
        "back_price": 100,
        "tod_price": 100
    },
    {
        "type": 3,
        "lotto": "213",
        "front_price": 100,
        "back_price": 100,
        "tod_price": 100
    },
    {
        "type": 3,
        "lotto": "231",
        "front_price": 100,
        "back_price": 100,
        "tod_price": 100
    },
    {
        "type": 3,
        "lotto": "312",
        "front_price": 100,
        "back_price": 100,
        "tod_price": 100
    },
    {
        "type": 3,
        "lotto": "321",
        "front_price": 100,
        "back_price": 100,
        "tod_price": 100
    }
]

Response Error

If general error

{
    "message": "Oops Something Went Wrong",
    "name": "SyntaxError"
}

If compiler error

{
    "message": "Expected \"%\", \"^\", [0-9], or end of input but \"a\" found.",
    "expected": [
        {
            "type": "class",
            "parts": [
                [
                    "0",
                    "9"
                ]
            ],
            "inverted": false,
            "ignoreCase": false
        },
        {
            "type": "literal",
            "text": "^",
            "ignoreCase": false
        },
        {
            "type": "literal",
            "text": "%",
            "ignoreCase": false
        },
        {
            "type": "end"
        }
    ],
    "found": "a",
    "location": {
        "start": {
            "offset": 0,
            "line": 1,
            "column": 1
        },
        "end": {
            "offset": 1,
            "line": 1,
            "column": 2
        }
    },
    "name": "SyntaxError"
}

License

MIT License

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago