New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

promptparse

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promptparse - npm Package Compare versions

Comparing version 0.5.0 to 1.0.0-rc

dist/index.d.mts

156

dist/index.d.ts

@@ -1,6 +0,150 @@

export { EMVCoQR, PromptParse, TLVTag } from './lib';
export * as TagUtils from './lib/TagUtils';
export { decode, encode, checksum, withCrcTag, get, tag } from './lib/TagUtils';
import PromptParse from './lib/PromptParse';
export declare const parse: typeof PromptParse.parse;
export default PromptParse;
interface TLVTag {
id: string;
value: string;
subTags?: TLVTag[];
length: number;
}
/**
* Decode TLV string into array of TLV Tags
*
* @param payload - TLV string
* @returns Array of TLV Tags
*/
declare function decode(payload: string): TLVTag[];
/**
* Encode TLV Tags array into TLV string
*
* @param tags - Array of TLV Tags
* @returns TLV string
*/
declare function encode(tags: TLVTag[]): string;
/**
* Generate CRC Checksum for provided string
*
* @param payload - Any string
* @returns CRC Checksum
*/
declare function checksum(payload: string): string;
/**
* Get TLV string combined with CRC Tag
*
* @param payload - TLV string (without CRC Tag)
* @param crcTagId - CRC Tag ID
* @returns TLV string + CRC Tag ID + CRC Length + CRC Checksum
*/
declare function withCrcTag(payload: string, crcTagId: string): string;
/**
* Get Tag or Sub-tag by Tag ID in array of TLV Tags
*
* @param tlvTags - Array of TLV Tags
* @param tagId - Target Tag ID
* @param subTagId - Target Sub-tag ID
* @returns Instance of Target Tag/Sub-tag
*/
declare function get(tlvTags: TLVTag[], tagId: string, subTagId?: string): TLVTag | undefined;
/**
* Create new TLV Tag
*
* @param tagId - Tag ID
* @param value - Tag Value
* @returns TLV Tag
*/
declare function tag(tagId: string, value: string): TLVTag;
declare class EMVCoQR {
private payload;
private tags;
constructor(payload: string, tags: TLVTag[]);
getTag(tagId: string, subTagId?: string): TLVTag | undefined;
getTagValue(tagId: string, subTagId?: string): string | undefined;
getTags(): TLVTag[];
getPayload(): string;
validate(crcTagId: string): boolean;
}
/**
* Parse any EMVCo-compatible QR Code data string
*
* @param payload - QR Code data string from the scanner
* @param strict - Validate CRC checksum before parsing the entire string
* @param subTags - Parse TLV Sub-tags (If exists)
* @returns QR Instance with TLV Tags
*/
declare function parse(payload: string, strict?: boolean, subTags?: boolean): EMVCoQR | null;
declare enum ProxyType {
'MSISDN' = "01",
'NATID' = "02",
'EWALLETID' = "03",
'BANKACC' = "04"
}
interface Config$3 {
type: keyof typeof ProxyType;
target: string;
amount?: number;
}
declare function anyId({ type, target, amount }: Config$3): string;
interface Config$2 {
billerId: string;
amount?: number;
ref1: string;
ref2?: string;
ref3?: string;
}
declare function billPayment({ billerId, amount, ref1, ref2, ref3 }: Config$2): string;
interface Config$1 {
mobileNo: string;
amount?: number;
message?: string;
}
/**
* Generate QR Code for TrueMoney Wallet
*
* This QR Code can also be scanned with other apps,
* just like a regular e-Wallet PromptPay QR
* but `Personal Message (Tag 81)` will be ignored.
*
* @returns QR Instance with TLV Tags
*/
declare function truemoney({ mobileNo, amount, message }: Config$1): string;
interface Config {
sendingBank: string;
transRef: string;
}
/**
* Generate Slip Verify QR Code
*
* This also called "Mini-QR" that embedded in slip used for verify transactions
*
* @returns QR Instance with TLV Tags
*/
declare function slipVerify$1({ sendingBank, transRef }: Config): string;
declare const index$1_anyId: typeof anyId;
declare const index$1_billPayment: typeof billPayment;
declare const index$1_truemoney: typeof truemoney;
declare namespace index$1 {
export {
index$1_anyId as anyId,
index$1_billPayment as billPayment,
slipVerify$1 as slipVerify,
index$1_truemoney as truemoney,
};
}
declare function slipVerify(payload: string): {
sendingBank: string;
transRef: string;
} | null;
declare const index_slipVerify: typeof slipVerify;
declare namespace index {
export {
index_slipVerify as slipVerify,
};
}
export { TLVTag, checksum, decode, encode, index$1 as generate, get, parse, tag, index as validate, withCrcTag };
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
function _array_like_to_array(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _array_without_holes(arr) {
if (Array.isArray(arr)) return _array_like_to_array(arr);
}
function _class_call_check(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
}
function _defineProperties(target, props) {
for(var i = 0; i < props.length; i++){
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _create_class(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
function _iterable_to_array(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _non_iterable_spread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _to_consumable_array(arr) {
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
}
function _type_of(obj) {
"@swc/helpers - typeof";
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
function _unsupported_iterable_to_array(o, minLen) {
if (!o) return;
if (typeof o === "string") return _array_like_to_array(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __defNormalProp = function(obj, key, value) {
return key in obj ? __defProp(obj, key, {
enumerable: true,
configurable: true,
writable: true,
value: value
}) : obj[key] = value;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
var __export = function(target, all) {
for(var name in all)__defProp(target, name, {
get: all[name],
enumerable: true
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parse = exports.tag = exports.get = exports.withCrcTag = exports.checksum = exports.encode = exports.decode = exports.TagUtils = exports.PromptParse = exports.EMVCoQR = void 0;
var lib_1 = require("./lib");
Object.defineProperty(exports, "EMVCoQR", { enumerable: true, get: function () { return lib_1.EMVCoQR; } });
Object.defineProperty(exports, "PromptParse", { enumerable: true, get: function () { return lib_1.PromptParse; } });
exports.TagUtils = __importStar(require("./lib/TagUtils"));
var TagUtils_1 = require("./lib/TagUtils");
Object.defineProperty(exports, "decode", { enumerable: true, get: function () { return TagUtils_1.decode; } });
Object.defineProperty(exports, "encode", { enumerable: true, get: function () { return TagUtils_1.encode; } });
Object.defineProperty(exports, "checksum", { enumerable: true, get: function () { return TagUtils_1.checksum; } });
Object.defineProperty(exports, "withCrcTag", { enumerable: true, get: function () { return TagUtils_1.withCrcTag; } });
Object.defineProperty(exports, "get", { enumerable: true, get: function () { return TagUtils_1.get; } });
Object.defineProperty(exports, "tag", { enumerable: true, get: function () { return TagUtils_1.tag; } });
const PromptParse_1 = __importDefault(require("./lib/PromptParse"));
exports.parse = PromptParse_1.default.parse;
exports.default = PromptParse_1.default;
var __copyProps = function(to, from, except, desc) {
if (from && typeof from === "object" || typeof from === "function") {
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
var _loop = function() {
var key = _step.value;
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: function() {
return from[key];
},
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
};
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
return to;
};
var __toCommonJS = function(mod) {
return __copyProps(__defProp({}, "__esModule", {
value: true
}), mod);
};
var __publicField = function(obj, key, value) {
__defNormalProp(obj, (typeof key === "undefined" ? "undefined" : _type_of(key)) !== "symbol" ? key + "" : key, value);
return value;
};
// src/index.ts
var src_exports = {};
__export(src_exports, {
checksum: function() {
return checksum;
},
decode: function() {
return decode;
},
encode: function() {
return encode;
},
generate: function() {
return generate_exports;
},
get: function() {
return get;
},
parse: function() {
return parse;
},
tag: function() {
return tag;
},
validate: function() {
return validate_exports;
},
withCrcTag: function() {
return withCrcTag;
}
});
module.exports = __toCommonJS(src_exports);
// src/utils/checksum.ts
var TABLE = [
0,
4129,
8258,
12387,
16516,
20645,
24774,
28903,
33032,
37161,
41290,
45419,
49548,
53677,
57806,
61935,
4657,
528,
12915,
8786,
21173,
17044,
29431,
25302,
37689,
33560,
45947,
41818,
54205,
50076,
62463,
58334,
9314,
13379,
1056,
5121,
25830,
29895,
17572,
21637,
42346,
46411,
34088,
38153,
58862,
62927,
50604,
54669,
13907,
9842,
5649,
1584,
30423,
26358,
22165,
18100,
46939,
42874,
38681,
34616,
63455,
59390,
55197,
51132,
18628,
22757,
26758,
30887,
2112,
6241,
10242,
14371,
51660,
55789,
59790,
63919,
35144,
39273,
43274,
47403,
23285,
19156,
31415,
27286,
6769,
2640,
14899,
10770,
56317,
52188,
64447,
60318,
39801,
35672,
47931,
43802,
27814,
31879,
19684,
23749,
11298,
15363,
3168,
7233,
60846,
64911,
52716,
56781,
44330,
48395,
36200,
40265,
32407,
28342,
24277,
20212,
15891,
11826,
7761,
3696,
65439,
61374,
57309,
53244,
48923,
44858,
40793,
36728,
37256,
33193,
45514,
41451,
53516,
49453,
61774,
57711,
4224,
161,
12482,
8419,
20484,
16421,
28742,
24679,
33721,
37784,
41979,
46042,
49981,
54044,
58239,
62302,
689,
4752,
8947,
13010,
16949,
21012,
25207,
29270,
46570,
42443,
38312,
34185,
62830,
58703,
54572,
50445,
13538,
9411,
5280,
1153,
29798,
25671,
21540,
17413,
42971,
47098,
34713,
38840,
59231,
63358,
50973,
55100,
9939,
14066,
1681,
5808,
26199,
30326,
17941,
22068,
55628,
51565,
63758,
59695,
39368,
35305,
47498,
43435,
22596,
18533,
30726,
26663,
6336,
2273,
14466,
10403,
52093,
56156,
60223,
64286,
35833,
39896,
43963,
48026,
19061,
23124,
27191,
31254,
2801,
6864,
10931,
14994,
64814,
60687,
56684,
52557,
48554,
44427,
40424,
36297,
31782,
27655,
23652,
19525,
15522,
11395,
7392,
3265,
61215,
65342,
53085,
57212,
44955,
49082,
36825,
40952,
28183,
32310,
20053,
24180,
11923,
16050,
3793,
7920
];
function crc16xmodem(data) {
var crc = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
for(var _iterator = data[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
var i = _step.value;
var b = i.charCodeAt(0);
var n = (b ^ crc >> 8) & 255;
crc = TABLE[n] ^ crc << 8;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return (crc ^ 0) & 65535;
}
// src/lib/tlv.ts
function decode(payload) {
var tags = [];
var idx = 0;
while(idx < payload.length){
var data = payload.substring(idx);
var id = data.substring(0, 2);
var length = parseInt(data.substring(2, 4));
var value = data.substring(4, 4 + length);
tags.push({
id: id,
length: length,
value: value
});
idx += length + 4;
}
return tags;
}
function encode(tags) {
var payload = "";
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
for(var _iterator = tags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
var tag2 = _step.value;
payload += tag2.id;
payload += ("00" + tag2.length).slice(-2);
if (tag2.subTags) {
payload += encode(tag2.subTags);
continue;
}
payload += tag2.value;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return payload;
}
function checksum(payload) {
var sum = crc16xmodem(payload, 65535).toString(16);
sum = ("0000" + sum.toUpperCase()).slice(-4);
return sum;
}
function withCrcTag(payload, crcTagId) {
payload += ("00" + crcTagId).slice(-2);
payload += "04";
payload += checksum(payload);
return payload;
}
function get(tlvTags, tagId, subTagId) {
var tag2 = tlvTags.find(function(t) {
return t.id == tagId;
});
if (subTagId) {
var _tag2_subTags;
return tag2 === null || tag2 === void 0 ? void 0 : (_tag2_subTags = tag2.subTags) === null || _tag2_subTags === void 0 ? void 0 : _tag2_subTags.find(function(s) {
return s.id == subTagId;
});
}
return tag2;
}
function tag(tagId, value) {
return {
id: tagId,
length: value.length,
value: value
};
}
// src/lib/EMVCoQR.ts
var EMVCoQR = /*#__PURE__*/ function() {
function EMVCoQR(payload, tags) {
_class_call_check(this, EMVCoQR);
__publicField(this, "payload");
__publicField(this, "tags");
this.payload = payload;
this.tags = tags;
}
_create_class(EMVCoQR, [
{
key: "getTag",
value: function getTag(tagId, subTagId) {
return get(this.tags, tagId, subTagId);
}
},
{
key: "getTagValue",
value: function getTagValue(tagId, subTagId) {
var _this_getTag;
return (_this_getTag = this.getTag(tagId, subTagId)) === null || _this_getTag === void 0 ? void 0 : _this_getTag.value;
}
},
{
key: "getTags",
value: function getTags() {
return this.tags;
}
},
{
key: "getPayload",
value: function getPayload() {
return this.payload;
}
},
{
key: "validate",
value: function validate1(crcTagId) {
var tags = _to_consumable_array(this.tags).filter(function(f) {
return f.id != crcTagId;
});
var expected = withCrcTag(encode(tags), crcTagId);
return this.payload === expected;
}
}
]);
return EMVCoQR;
}();
// src/lib/parser.ts
function parse(payload) {
var strict = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false, subTags = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
if (!payload.match(/^\d{4}.+/)) {
return null;
}
if (strict) {
var expected = payload.slice(-4);
var calculated = checksum(payload.slice(0, -4));
if (expected != calculated) return null;
}
var tags = decode(payload);
if (tags.length == 0) {
return null;
}
if (subTags) {
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
for(var _iterator = tags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
var tag2 = _step.value;
if (typeof tag2.value !== "string" || !tag2.value.match(/^\d{4}.+/)) {
continue;
}
var sub = decode(tag2.value);
if (sub.every(function(val) {
return val.length > 0 && val.length === val.value.length;
})) {
tag2.subTags = sub;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
return new EMVCoQR(payload, tags);
}
// src/generate/index.ts
var generate_exports = {};
__export(generate_exports, {
anyId: function() {
return anyId;
},
billPayment: function() {
return billPayment;
},
slipVerify: function() {
return slipVerify;
},
truemoney: function() {
return truemoney;
}
});
// src/generate/promptpay/AnyID.ts
var ProxyType = /* @__PURE__ */ function(ProxyType2) {
ProxyType2["MSISDN"] = "01";
ProxyType2["NATID"] = "02";
ProxyType2["EWALLETID"] = "03";
ProxyType2["BANKACC"] = "04";
return ProxyType2;
}(ProxyType || {});
function anyId(param) {
var type = param.type, target = param.target, amount = param.amount;
if (type == "MSISDN") {
target = ("0000000000000" + target.replace(/^0/, "66")).slice(-13);
}
var tag29 = encode([
tag("00", "A000000677010111"),
tag(ProxyType[type], target)
]);
var payload = [
tag("00", "01"),
tag("01", !amount ? "11" : "12"),
tag("29", tag29),
tag("53", "764"),
tag("58", "TH")
];
if (amount) {
payload.push(tag("54", amount.toFixed(2)));
}
return withCrcTag(encode(payload), "63");
}
// src/generate/promptpay/BillPayment.ts
function billPayment(param) {
var billerId = param.billerId, amount = param.amount, ref1 = param.ref1, ref2 = param.ref2, ref3 = param.ref3;
var tag30 = [
tag("00", "A000000677010112"),
tag("01", billerId),
tag("02", ref1)
];
if (ref2) {
tag30.push(tag("03", ref2));
}
var payload = [
tag("00", "01"),
tag("01", !amount ? "11" : "12"),
tag("30", encode(tag30)),
tag("53", "764"),
tag("58", "TH")
];
if (amount) {
payload.push(tag("54", amount.toFixed(2)));
}
if (ref3) {
payload.push(tag("62", encode([
tag("07", ref3)
])));
}
return withCrcTag(encode(payload), "63");
}
// src/generate/TrueMoney.ts
function encodeTag81(message) {
return message.split("").map(function(c) {
return c.charCodeAt(0).toString(16).padStart(4, "0");
}).join("").toUpperCase();
}
function truemoney(param) {
var mobileNo = param.mobileNo, amount = param.amount, message = param.message;
var tag29 = encode([
tag("00", "A000000677010111"),
tag("03", "14000".concat(mobileNo))
]);
var payload = [
tag("00", "01"),
tag("01", !amount ? "11" : "12"),
tag("29", tag29),
tag("53", "764"),
tag("58", "TH")
];
if (amount) {
payload.push(tag("54", amount.toFixed(2)));
}
if (message) {
payload.push(tag("81", encodeTag81(message)));
}
return withCrcTag(encode(payload), "63");
}
// src/generate/SlipVerify.ts
function slipVerify(param) {
var sendingBank = param.sendingBank, transRef = param.transRef;
var payload = [
tag("00", encode([
tag("00", "000001"),
tag("01", sendingBank),
tag("02", transRef)
])),
tag("51", "TH")
];
return withCrcTag(encode(payload), "91");
}
// src/validate/index.ts
var validate_exports = {};
__export(validate_exports, {
slipVerify: function() {
return slipVerify2;
}
});
// src/validate/SlipVerify.ts
function slipVerify2(payload) {
var ppqr = parse(payload, true);
var apiType = ppqr === null || ppqr === void 0 ? void 0 : ppqr.getTagValue("00", "00");
var sendingBank = ppqr === null || ppqr === void 0 ? void 0 : ppqr.getTagValue("00", "01");
var transRef = ppqr === null || ppqr === void 0 ? void 0 : ppqr.getTagValue("00", "02");
if (apiType !== "000001" || !sendingBank || !transRef) {
return null;
}
return {
sendingBank: sendingBank,
transRef: transRef
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
checksum: checksum,
decode: decode,
encode: encode,
generate: generate,
get: get,
parse: parse,
tag: tag,
validate: validate,
withCrcTag: withCrcTag
});
//# sourceMappingURL=index.js.map

4

LICENSE.md
MIT License
Copyright (c) 2022 Maythiwat Chomchuen
Copyright (c) 2023 Maythiwat Chomchuen

@@ -21,2 +21,2 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
{
"name": "promptparse",
"version": "0.5.0",
"version": "1.0.0-rc",
"description": "All-in-one JS library for PromptPay & EMVCo QR Codes",
"author": "Maythiwat Chomchuen <maythiwat.chom@gmail.com>",
"license": "MIT",
"author": "Maythiwat Chomchuen <maythiwat.chom@gmail.com>",
"repository": {
"type": "git",
"url": "https://github.com/maythiwat/promptparse.git"
},
"description": "💸 PromptPay (and EMVCo-compatible) QR Code Payload Parser and Generator",
"keywords": [

@@ -20,16 +16,38 @@ "emvco",

],
"repository": {
"type": "git",
"url": "https://github.com/maythiwat/promptparse.git"
},
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"module": "dist/index.mjs",
"browser": "dist/index.global.js",
"exports": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"files": [
"dist/**/*"
],
"engines": {
"pnpm": ">=8"
},
"devDependencies": {
"@types/node": "^18.15.13",
"rimraf": "^5.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
"@swc/core": "^1.3.91",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"eslint": "^8.50.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"tsup": "^7.2.0",
"typescript": "^5.2.2"
},
"scripts": {
"build": "rimraf dist && tsc --build"
"lint": "prettier --check . && eslint .",
"format": "prettier --write . && eslint --fix .",
"build": "rimraf dist && tsup"
}
}

@@ -1,44 +0,22 @@

![PromptParse](https://user-images.githubusercontent.com/61514399/202692697-c6bbade6-f5b4-4a60-8989-5d80ba31f58e.png)
![PromptParse](https://github.com/maythiwat/promptparse/assets/23092256/889e8f80-b1b3-44b2-ace5-ffbbce6e673b)
# PromptParse
💸 PromptPay (and EMVCo-compatible) QR Code Payload Parser and Generator
All-in-one JS library for PromptPay & EMVCo QR Codes
## Features
- Parses PromptPay or other EMVCo-compatible QR Code Data
- Construct TLV Tags into QR Code Data (uses to create QR Code)
- Pre-made generators for PromptPay and other Thai QR Standards (and non-standards)
## Usage
### Parsing data and get value from tag
```ts
import { parse } from 'promptparse'
- **Parse** &mdash; PromptPay & EMVCo QR Code data strings into object
- **Generate** &mdash; QR Code data from pre-made templates (for example: PromptPay AnyID, PromptPay Bill Payment, TrueMoney, etc.)
- **Manipulate** &mdash; any values from parsed QR Code data (for example: transfer amount, account number) and encodes back into QR Code data
- **Validate** &mdash; checksum and data structure for known QR Code formats (for example: Slip Verify API Mini QR)
// Example data
const ppqr = parse('000201010211...')
## References
// Get Tag ID '00'
ppqr.getTagValue('00') // Returns '01'
```
### Build QR data
```ts
import { encode, tag, withCrcTag } from 'promptparse'
// Example data
const data = [
tag('00', '01'),
tag('01', '11'),
// ...
]
// Set CRC Tag ID '63'
withCrcTag(encode(data), '63') // Returns '000201010211...'
```
## References
- [EMV QR Code](https://www.emvco.com/emv-technologies/qrcodes/)
- [Thai QR Payment Standard](https://www.bot.or.th/Thai/PaymentSystems/StandardPS/Documents/ThaiQRCode_Payment_Standard.pdf)
- [Thai QR Payment Standard](https://www.bot.or.th/content/dam/bot/fipcs/documents/FPG/2562/ThaiPDF/25620084.pdf)
- [Slip Verify API Mini QR Data](https://developer.scb/assets/documents/documentation/qr-payment/extracting-data-from-mini-qr.pdf)
## License
This project is MIT licensed (see [LICENSE.md](LICENSE.md))
This project is MIT licensed (see [LICENSE.md](LICENSE.md))
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc