@esi_package/esi_ew_ui_common (1.0.3)
Published 2025-06-06 12:19:58 +07:00 by esirepository
Installation
@esi_package:registry=
npm install @esi_package/esi_ew_ui_common@1.0.3
"@esi_package/esi_ew_ui_common": "1.0.3"
About this package
# ESI_FORM_COMMON
Build it
run: npm install
run: npm run build หรือ rmdir /s /q dist && yarn build
run: npm publish
Usage
| Note: This is a private package so it needs a Token that has read permission from the package owner to install and update
- Put Token in file
.npmrc
@esi_package:registry=http://158.108.215.151:8081/api/packages/esirepository/npm/
//npm.pkg.github.com/:_authToken={{YOUR_TOKEN}}
- Install package
npm install @esi_package/esi_form_common
- PLease regularly update package to latest version.
npm install @esi_package/esi_form_common@latest
How to use this package
import from import e from "@esi_package/esi_form_common"
- to get a value
import e from "@esi_package/esi_form_common";
e.Gender.enums.Male; // 1
- to get a
enum object
fromenum code
with default object
import e from "@esi_package/esi_form_common";
// Gender.getEnumValue(string | number, defaultObject)
e.Gender.getEnumValue("Male"); // {value:1, th:"ชาย",en:"male"}
e.Gender.getEnumValue("MaleMale", {
value: -1,
th: "not found",
en: "not found",
}); // {value:-1, th:"not found",en:"not found"}
- to get a
enum object
fromenum value
with default object
import e from "@esi_package/esi_common";
e.Gender.getEnumValue(1); // {value:1, th:"ชาย", en:"male"}
e.Gender.getEnumValue(0); // {value:0, th:"ไม่ระบุ", en:"not specified"}
e.Gender.getEnumValue(e.Gender.enums.Male); // {value:1 , th:"ชาย", en:"male"}
e.Gender.getEnumValue(100, {
value: -1,
th: "not found",
en: "not found",
}); // {value:-1, th:"not found",en:"not found"}
e.Gender.getEnumValue(100); // {value:-1, th:"not found",en:"not found"}
- to get a list of
enum object
import e from "@esi_package/esi_form_common";
const genderArr = e.Gender.entries;
// [{key: "Male", value : 1, th: "ชาย", en: "male"},
// {key:"Female", value: 2, th: "หญิง" en: "female"}
// ...]
- work with
class validators
// file `dto/something.dto.ts`
import e from "@esi_package/esi_form_common"
export class SomethingDto{
...
@IsEnum(e.Gender.enums)
Gender: Number
...
}
How to generate a Token (Only for package owner)
- Go to settings
- Settings > Developer Settings > Personal access tokens > Tokens (Classic)
- Generate a token with a name and desired expiration date.
- Select permission to read a package.
How to add data
- In folder
src/enumsBaseObjects
. Create a BaseObject that has the following structure
| Note that declare object as const
is required
const baseObject = {
[key: string]: { // key is the enum code for example: Male
value: number;
th: string;
en: string;
}
} as const
- Create and export a
Enum
Class with BaseObject and default Value as a input
| Note that type of DefaultValue must match a type of BaseObject
import { Enums } from "../enumsClass";
export const EnumName = new Enums(BaseObject, DefaultObject);
Example:
import { Enums } from "../enumsClass";
const GenderObj = {
Female: {
value: 2,
th: "หญิง",
en: "female",
},
Male: {
value: 1,
th: "ชาย",
en: "male",
},
Other: {
value: 0,
th: "อื่นๆ",
en: "other",
},
} as const;
export const Gender = new Enums(GenderObj, {
value: -1,
en: "not found",
th: "not found",
});
- In file
index.ts
. Import a enum Class and register ine
object.
import { Gender } from "./enumsBaseObjects/person";
const e={
...,
...,
Gender
}
Package versioning
- This package have github workflow to automatically
patch
npm version oin every push commit. - You can change version in
package.js
{
"name": "@npinyada/esi_common",
"version": "1.0.14",
...
}
- with commit message start with
[SKIP] commit message...
can skip redeploy and versioning a package.
Dependencies
Dependencies
ID | Version |
---|---|
typescript | ^5.4.5 |
Development Dependencies
ID | Version |
---|---|
ts-node | ^10.9.2 |