0.19.2 • Published 3 years ago

@kurone-kito/dantalion-i18n v0.19.2

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

🦁 Dantalion: i18n resources library

npm version lerna

This package provides a function that infers the personality details from the specified birthday. By using this package, you can quickly implement birthday divination in your Node.js apps. Its calculation is using the method of Four Pillars of Destiny (Ba-Zi).

This package is a library that obtains human-readable (Markdown format) details for the output of the @kurone-kito/dantalion-core package.

This library uses the Intl API to determine the language and outputs it in the appropriate language. It's only in Japanese and partly English yet, but we'll gradually support multiple languages.

Usage

Require: Node.js >= v12.1

Add to dependency

npm install -S @kurone-kito/dantalion-core @kurone-kito/dantalion-i18n

Get the details of the personality

const { getPersonality } = require('@kurone-kito/dantalion-core');
const { genius } = require('@kurone-kito/dantalion-i18n');

const personality = getPersonality('1993-10-09');
console.log(personality.inner); // === '555'

const result = genius.getValue(personality.inner);

console.log(JSON.stringify(result));

Result

In strictly, The function gets the raw object, not the JSON. Since it's a long sentence, it omitted some parts.

{
  "name": "Easygoing type",
  "summary": "Balanced, capable and caring, a heroic position.",
  "detail": [
    "Many people have an air of all-around competence and boss authority, like an executive employee.",
    :
    :
  ],
  "weak": [
    "They don't like to apologize even when it is their fault. Even if they have apologetic, they are not very good at expressing it."
    :
    :
  ],
  "strategy": [
    "They can do everything on their own, so they tend to take care of everything on their own. When you entrust them with something, be careful not to let them do too much."
  ]
}

API

createAccessors(t: i18next.TFunction): Accessors

Create the concreted accessors collection from the i18next instance

Arguments

NameTypeDefaultsDescription
ti18next.TFunction(Required)Specify the i18next instance

Returns

Accessors: The instance of the concreted accessors collection

createAccessorsAsync(lng?: string, additions?: i18next.ResourceLanguage): Promise<Accessors & i18next.WithT>

Create the concreted accessors collection asynchronously

It is a synonym function that combines createAccessors() and createTAsync().

Arguments

NameTypeDefaultsDescription
lngstring?(*)The language to use
additionsi18next.ResourceLanguage?undefinedSpecify the additional resources if you need

(*: If omitted, the language used is detected from the current environment. See: useLocale())

Returns

Promise<Accessors & i18next.WithT>: The instance of the concreted accessors collection

createTAsync(options?: CreateTAsyncOptions): Promise<i18next.TFunction>

Create and initialize the i18next instance asynchronously

Arguments

NameTypeDefaultsDescription
optionsCreateTAsyncOptions?{}The options

Returns

Promise<i18next.TFunction>: The i18next instance which already initialized the resources.

fallbackLanguage: 'en'

The language that uses as a fallback.

getDetailMarkdown(accessors: Accessors, genius?: Genius): string

Get the personality information.

Arguments

NameTypeDefaultsDescription
accessorsAccessors(Required)The accessors instance for resources.
geniusGenius?undefinedThe types of personality.

Returns

string: The string that the personality information as the Markdown format.

If you specified the undefined value as an argument or omitted it, it would be a list of the available types.

getLocale(): string | undefined

Get the locale information from the Intl API.

Arguments

(None)

Returns

string: The locale string e.g. en-US.

getPersonalityMarkdown(accessors: Accessors, birth: string | number | Date): string

Get the personality information corresponding to the specified birthday.

Arguments

NameTypeDefaultsDescription
geniusAccessors(Required)The accessors instance for resources.
birthstring \| number \| Date(Required)Specify a birthday within the range from February 1, 1873, to December 31, 2050. Ignore the time information.

Returns

string: The string that the personality information as the Markdown format. If the date is over the range, it will be error message.

locales: Record<string, string>

The locales table.

The property keys have ISO 639-1 string and values exact name.

Type definitions (for TypeScript)

The strings contained in the object are in Markdown format. In the case of an array of strings, the elements separate for each paragraph.

Accessors

The type definition of the concreted accessors collection

interface Accessors {
  readonly brain: DetailAccessor<DetailsType, Brain>;
  readonly communication: DetailAccessor<DetailsType, Communication>;
  readonly genius: DetailAccessor<
    PersonalityType,
    Genius,
    PersonalityDetailType
  >;
  readonly lifeBase: DetailAccessor<
    DetailsBaseType<string[]>,
    LifeBase,
    string
  >;
  readonly management: DetailAccessor<DetailsType, Management>;
  readonly motivation: DetailAccessor<string, Motivation, string>;
  readonly position: DetailAccessor<DetailsType, Position>;
  readonly potential?: DetailAccessor<
    readonly string[],
    readonly [Potential, Potential]
  >;
  readonly response: DetailAccessor<DetailsType, Response>;
  readonly vector: DetailAccessor<VectorType, Vector>;
  getDescription(type?: string): DesctiptionsType;
}
PropertyTypeDescription
brainDetailAccessor<DetailsType, Brain>The instance provides a set of functions that retrieve human-readable resources related to the thought method.
communicationDetailAccessor<DetailsType, Communication>The instance provides a set of functions that retrieve human-readable resources related to dialogue policy.
geniusDetailAccessor<PersonalityType, Genius, PersonalityDetailType>The instance provides a set of functions that retrieve human-readable resources related to natural personality.
lifeBaseDetailAccessor<DetailsBaseType<string[]>, LifeBase, string>The instance provides a set of functions that retrieve human-readable resources related to the base of ego type.
managementDetailAccessor<DetailsType, Management>The instance provides a set of functions that retrieve human-readable resources related to risk and return thinking in specific people.
motivationDetailAccessor<string, Motivation, string>The instance provides a set of functions that retrieve human-readable resources related to to an environment that is easy to get motivated.
positionDetailAccessor<DetailsType, Position>The instance provides a set of functions that retrieve human-readable resources related to a talented role.
potentialDetailAccessor<readonly string[], readonly [Potential, Potential]>The instance provides functions that retrieve human-readable resources related to that can exert when taking action.
responseDetailAccessor<DetailsType, Response>The instance provides a set of functions that retrieve human-readable resources related to on-site or behind.
vectorDetailAccessor<VectorType, Vector>The instance provides a set of functions that retrieve human-readable resources related to the major classification of personality.
Method definitionDescription
getDescription(type?: string): DesctiptionsTypeGet the resources of the descriptions heading.

CreateTAsyncOptions

The type definition that the options of the createTAsync function.

interface CreateTAsyncOptions {
  readonly additions?: i18next.ResourceLanguage;
  readonly lng?: string;
  readonly use?:
    | i18next.Module
    | i18next.Newable<i18next.Module>
    | i18next.ThirdPartyModule[]
    | i18next.Newable<i18next.ThirdPartyModule>[];
}
PropertyTypeDescription
additionsi18next.ResourceLanguage \| undefinedSpecify the additional resources if you need
lngstring \| undefinedThe language to use. If omitted, the language used is detected from the current environment.
use(*)The use function is there to load additional plugins to i18next.

(*: See the type definition as it is long :/)

DesctiptionsType

The type definition that the resources of description.

interface DesctiptionsType {
  readonly cc: string;
  readonly detail: string;
  readonly details: string;
  readonly genius1: string;
  readonly genius2: string;
  readonly invalid: string;
  readonly personality: string;
  readonly strategy: string;
  readonly weak: string;
}
PropertyTypeDescription
ccstringThe title of personality code.
detailstringThe title of the detail.
detailsstringThe title of the details list.
genius1stringThe detail of the genius.
genius2stringThe detail of the genius.
invalidstringThe error message when specified invalid birthday.
personalitystringThe title of personality.
strategystringThe strategy.
weakstringThe weak points.

DetailAccessor<T, K, D>

The type definition with a function to access a resource of the specific category.

interface DetailAccessor<
  T extends i18next.TFunctionResult,
  K,
  D extends DetailsBaseType | string = DetailsBaseType
> {
  getByKey(key: K): T;
  getCategoryDetail(): D;
}
TypeConstraintDescription
Ti18next.TFunctionResultThe type of resource as a return value.
K(none)The type for the resource key.
DDetailsBaseType \| stringThe type of resource as a return value of category detail.
Method definitionDescription
getByKey(key: K): TThe function acquires the resource corresponding to the key.
getCategoryDetail(): DThe function acquires the resource corresponding to the specific category.

DetailsBaseType<T>

The type definition that the pair of name and detail.

interface DetailsBaseType<T = string> {
  readonly detail: T;
  readonly name: string;
}
TypeConstraintDescription
TstringThe type of details.
PropertyTypeDescription
detailstringThe detail.
namestringThe resource name as a heading.

DetailsType

The type definition that the name, detail and more descriptions.

interface DetailsType {
  readonly detail: string;
  readonly name: string;
  readonly more: readonly string[];
}
PropertyTypeDescription
detailstringThe detail.
morereadonly string[]The more detailed descriptions.
namestringThe resource name as a heading.

PersonalityDetailBaseType

The type definition that the details of personality.

export interface PersonalityDetailBaseType {
  readonly inner: string;
  readonly outer: string;
  readonly workStyle: string;
}
PropertyTypeDescription
innerstringThe resource of inner personality.
outerstringThe resource of outer personality.
workStylestringThe resource of personality at working.

PersonalityDetailType

The type definition that the details of personality.

export interface PersonalityDetailType {
  readonly descriptions: PersonalityDetailBaseType;
  readonly detail: string;
  readonly inner: string;
  readonly name: string;
  readonly outer: string;
  readonly workStyle: string;
}
PropertyTypeDescription
descriptionsPersonalityDetailBaseTypeLong descriptions.
detailstringThe detail.
innerstringThe resource of inner personality.
namestringThe resource name as a heading.
outerstringThe resource of outer personality.
workStylestringThe resource of personality at working.

PersonalityType

A type definition of a structure that stores a description of a particular person's personality.

interface PersonalityType {
  readonly detail: readonly string[];
  readonly name: string;
  readonly strategy: readonly string[];
  readonly summary: string;
  readonly weak: readonly string[];
}
PropertyTypeDescription
detailreadonly string[]The detail.
namestringThe resource name.
strategyreadonly string[]The strategies for communicating with people of this personality type.
summarystringThe short summary as a heading.
weakreadonly string[]The weak points.

VectorType

A type definition of a structure that stores a description of a personality type.

interface VectorType {
  readonly detail: string;
  readonly name: string;
  readonly strategy: readonly string[];
}
PropertyTypeDescription
detailstringThe detail.
namestringThe resource name as a heading.
strategyreadonly string[]The strategies for communicating with people of this personality type.

See also

License

MIT

0.19.2

3 years ago

0.19.1

3 years ago

0.19.0

3 years ago

0.18.0

3 years ago

0.17.0

3 years ago

0.16.0

3 years ago

0.15.0

3 years ago

0.14.0

3 years ago

0.13.2

3 years ago

0.13.0

3 years ago

0.13.1

3 years ago

0.12.2

3 years ago

0.12.3

3 years ago

0.10.0

3 years ago

0.11.0

3 years ago

0.9.0

3 years ago

0.12.0

3 years ago

0.11.1

3 years ago

0.8.0

3 years ago

0.12.1

3 years ago

0.11.2

3 years ago

0.5.0

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.5.1

3 years ago

0.3.2

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.5

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago