Skip to content

Commit

Permalink
Merge branch 'release/2.0.0-rc.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
lisez committed May 10, 2024
2 parents c11889b + d645ed8 commit 4e106df
Show file tree
Hide file tree
Showing 21 changed files with 3,344 additions and 4,647 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

12 changes: 0 additions & 12 deletions .eslintrc.yml

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: NodeJS CI

on:
- push

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['18.x', '20.x', '22.x']
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: yarn install --frozen-lockfile
- run: yarn test
18 changes: 18 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Publish Package to npmjs
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- run: yarn
- run: yarn publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ assert.equal(test9, '下降壹佰貳拾參');
// Support Simplified/Traditional Chinese, default: `zh-tw`
const test10 = converter('-123', { lang: 'zh-cn' });
assert.equal(test10, '负壹佰贰拾参');

```

### `Important`: BigInt and Number
Expand Down
17 changes: 17 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import globals from 'globals';
import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';

export default [
{ languageOptions: { globals: { ...globals.browser, ...globals.node } } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{
rules: {
'@typescript-eslint/ban-ts-comment': 0,
},
},
{
ignores: ['dist'],
},
];
31 changes: 17 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lib-arabic-chinese",
"version": "1.3.5",
"version": "2.0.0-rc.1",
"description": "A library for converting from Arabic numbers to Chinese numbers",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -40,18 +40,21 @@
"demo": "ts-node --files ./demo/index.ts"
},
"devDependencies": {
"@types/jest": "^24.0.25",
"@types/webpack": "^4.41.0",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-plugin-import": "^2.19.1",
"jest": "^24.9.0",
"prettier": "^1.19.1",
"ts-jest": "^24.2.0",
"ts-loader": "^6.2.1",
"ts-node": "^8.5.4",
"typescript": "^3 || ^4",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10"
"@eslint/js": "^9.2.0",
"@types/jest": "^29.5.12",
"@types/webpack": "^5.28.5",
"eslint": "^9.2.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.29.1",
"globals": "^15.2.0",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"ts-jest": "^29.1.2",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"typescript-eslint": "^7.8.0",
"webpack": "^5.91.0",
"webpack-cli": "^5.1.4"
}
}
17 changes: 9 additions & 8 deletions src/Digit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type TDigitConfig = {
export const defaultConfig: TDigitConfig = {
caseType: 'upper',
placeUnit: -1,
lang: 'zh-tw'
lang: 'zh-tw',
};

export default class Digit extends String {
Expand All @@ -19,13 +19,13 @@ export default class Digit extends String {
prev: Digit;
next: Digit;

// @ts-ignore
// @ts-expect-error
constructor(digit: number | string, config: Partial<TDigitConfig> = {}) {
// @ts-ignore
// @ts-expect-error
this = new String(digit);
// @ts-ignore
// @ts-expect-error
this.__proto__ = Digit.prototype;
// @ts-ignore
// @ts-expect-error
this.config = { ...defaultConfig, ...config };

if (String(digit).length > 1 || String(digit).length === 0) {
Expand Down Expand Up @@ -133,8 +133,8 @@ export default class Digit extends String {
return unit > 0
? unit
: this.config.placeUnit > 44
? this.config.placeUnit % 44
: this.config.placeUnit;
? this.config.placeUnit % 44
: this.config.placeUnit;
}

private get unit(): string {
Expand All @@ -145,7 +145,8 @@ export default class Digit extends String {
if (this.unitType <= 3) {
const index = String(this.unitType) as keyof (
| TDigitMapping['lowerCaseUnitMapping']
| TDigitMapping['upperCaseUnitMapping']);
| TDigitMapping['upperCaseUnitMapping']
);
return this.mapping.unit[index];
}

Expand Down
18 changes: 9 additions & 9 deletions src/Signed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const defaultSignedConfig: TSignedConfig = {
showPlusSigned: false,
showMinusSigned: true,
signedOutput: {},
lang: 'zh-tw'
lang: 'zh-tw',
};

export default class Signed extends String {
Expand All @@ -31,27 +31,27 @@ export default class Signed extends String {

config: TSignedConfig;

// @ts-ignore
// @ts-expect-error
constructor(signed: string, config: RecursivePartial<TSignedConfig> = {}) {
// @ts-ignore
// @ts-expect-error
this = new String(signed);
// @ts-ignore
// @ts-expect-error
this.__proto__ = Signed.prototype;
// @ts-ignore
// @ts-expect-error
this.setup(config);

if (String(signed).length > 1 || String(signed).length === 0) {
throw new TypeError('invalid signed length');
}

// @ts-ignore
// @ts-expect-error
if (!this.isPlus && !this.isMinus) {
throw new TypeError('signed should be plus or minus');
}
}

private get mapping(): { symbol: TSignedMapping } {
let symbol = <TSignedMapping>this.config.signedOutput;
const symbol = <TSignedMapping>this.config.signedOutput;
return { symbol };
}

Expand Down Expand Up @@ -87,8 +87,8 @@ export default class Signed extends String {
signedOutput: {
...defaultSignedConfig.signedOutput,
...((config || {}).lang ? SignedLang[config.lang!] : {}),
...((config || {}).signedOutput || {})
}
...((config || {}).signedOutput || {}),
},
};

return this;
Expand Down
9 changes: 3 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const defaultConverterConfig: IConverterConfig = {
prefix: '',
suffix: '',
prefixPosition: 'after-signed',
lang: 'zh-tw'
lang: 'zh-tw',
};

function objectize(numbers: string[], config: IConverterConfig): Digit[] {
Expand All @@ -41,7 +41,7 @@ function isValidNumberText(nText: string): boolean {

export default function main(
text: string | number | bigint,
userConfig: Partial<IConverterConfig> = defaultConverterConfig
userConfig: Partial<IConverterConfig> = defaultConverterConfig,
): string {
if (typeof text === 'number' || typeof text === 'bigint') {
return main(text.toString(), userConfig);
Expand All @@ -66,10 +66,7 @@ export default function main(
}

const numberText = hasSigned ? toNormal.slice(1) : toNormal;
const numberToChars = numberText
.replace(/[,]/g, '')
.split('')
.reverse();
const numberToChars = numberText.replace(/[,]/g, '').split('').reverse();

const numberToDigits = objectize(numberToChars, config);
const number = numberToDigits.reduce((p, c) => c.toString() + p, '');
Expand Down
2 changes: 1 addition & 1 deletion src/lang/Digit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type TDigitLang = { [langCode in TLangCode]: TDigitMapping };

const langs: TDigitLang = {
'zh-tw': zhTW,
'zh-cn': zhCN
'zh-cn': zhCN,
};

export default langs;
8 changes: 4 additions & 4 deletions src/lang/Digit/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const mapping: TDigitMapping = {
upperCaseUnitMapping: {
'1': '拾',
'2': '佰',
'3': '仟'
'3': '仟',
},

lowerCaseUnitMapping: {
'1': '十',
'2': '百',
'3': '千'
'3': '千',
},

largeUnitMapping: {
Expand All @@ -28,8 +28,8 @@ const mapping: TDigitMapping = {
'32': '沟',
'36': '涧',
'40': '正',
'44': '载'
}
'44': '载',
},
};

export default mapping;
8 changes: 4 additions & 4 deletions src/lang/Digit/zh-tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const mapping: TDigitMapping = {
upperCaseUnitMapping: {
'1': '拾',
'2': '佰',
'3': '仟'
'3': '仟',
},

lowerCaseUnitMapping: {
'1': '十',
'2': '百',
'3': '千'
'3': '千',
},

largeUnitMapping: {
Expand All @@ -28,8 +28,8 @@ const mapping: TDigitMapping = {
'32': '溝',
'36': '澗',
'40': '正',
'44': '載'
}
'44': '載',
},
};

export default mapping;
2 changes: 1 addition & 1 deletion src/lang/Signed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type TSignedLang = { [langCode in TLangCode]: TSignedMapping };

const langs: TSignedLang = {
'zh-tw': zhTW,
'zh-cn': zhCN
'zh-cn': zhCN,
};

export default langs;
2 changes: 1 addition & 1 deletion src/lang/Signed/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TSignedMapping } from './index';

const mapping: TSignedMapping = {
plusSigned: '正',
minusSigned: '负'
minusSigned: '负',
};

export default mapping;
2 changes: 1 addition & 1 deletion src/lang/Signed/zh-tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TSignedMapping } from './index';

const mapping: TSignedMapping = {
plusSigned: '正',
minusSigned: '負'
minusSigned: '負',
};

export default mapping;
4 changes: 2 additions & 2 deletions tests/dist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import zhCharMapping from './utils/zhCharsMapping';

for (const testset of TestCases) {
describe(testset.set, () => {
for (let [tNumber, eValue] of Object.entries(testset.data)) {
for (const [tNumber, eValue] of Object.entries(testset.data)) {
test(`(String) ${tNumber} -> ${eValue}`, () => {
const aValue = Converter(tNumber, <IConverterConfig>(testset.options || {}));
expect(aValue).toEqual(eValue);
Expand All @@ -13,7 +13,7 @@ for (const testset of TestCases) {
// to simple
const toSimple = (<string>eValue)
.split('')
.map(c => zhCharMapping[c] || c)
.map((c) => zhCharMapping[c] || c)
.join('');
test(`(Simple) ${tNumber} -> ${toSimple}`, () => {
const opt = <IConverterConfig>{ ...(testset.options || {}), lang: 'zh-cn' };
Expand Down
4 changes: 2 additions & 2 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import zhCharMapping from './utils/zhCharsMapping';

for (const testset of TestCases) {
describe(testset.set, () => {
for (let [tNumber, eValue] of Object.entries(testset.data)) {
for (const [tNumber, eValue] of Object.entries(testset.data)) {
test(`(String) ${tNumber} -> ${eValue}`, () => {
const aValue = Converter(tNumber, <IConverterConfig>(testset.options || {}));
expect(aValue).toEqual(eValue);
Expand All @@ -13,7 +13,7 @@ for (const testset of TestCases) {
// to simple
const toSimple = (<string>eValue)
.split('')
.map(c => zhCharMapping[c] || c)
.map((c) => zhCharMapping[c] || c)
.join('');
test(`(Simple) ${tNumber} -> ${toSimple}`, () => {
const opt = <IConverterConfig>{ ...(testset.options || {}), lang: 'zh-cn' };
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/zhCharsMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const zhCharMapping: { [char: string]: string } = {
: '沟',
: '涧',
// 正: '正',
: '载'
: '载',
};

export default zhCharMapping;
Loading

0 comments on commit 4e106df

Please sign in to comment.