@esi_package/esi_form_common (1.0.29)

Published 2024-09-20 14:08:42 +07:00 by esirepository

Installation

@esi_package:registry=
npm install @esi_package/esi_form_common@1.0.29
"@esi_package/esi_form_common": "1.0.29"

About this package

# ESI_FORM_COMMON

Link รายละเอียด Enum

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

  1. 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}}
  1. Install package
npm install @esi_package/esi_form_common
  1. 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"

  1. to get a value
import e from "@esi_package/esi_form_common";

e.Gender.enums.Male; // 1
  1. to get a enum object from enum 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"}
  1. to get a enum object from enum 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"}
  1. 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"}
// ...]
  1. 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)

  1. Go to settings

image

  1. Settings > Developer Settings > Personal access tokens > Tokens (Classic)

image

  1. Generate a token with a name and desired expiration date.
  2. Select permission to read a package.

image

How to add data

  1. 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
  1. 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",
});
  1. In file index.ts. Import a enum Class and register in e 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
Details
npm
2024-09-20 14:08:42 +07:00
5
ISC
20 KiB
Assets (1)
Versions (30) View all
1.0.33 2024-10-27
1.0.32 2024-10-11
1.0.31 2024-10-11
1.0.30 2024-09-26
1.0.29 2024-09-20