简体   繁体   English

如何在 Angular 或 Typescript 中将数字转换为波斯语单词?

[英]How can I convert a number into Persian words in Angular or Typescript?

I want to convert numbers to words in my Angular project like this:我想在我的 Angular 项目中将数字转换为单词,如下所示:

1372 --> یک هزار و سیصد و هفتاد و دو

I found a package called persianJS that supports this conversion but it can't be imported in TypeScript , I tried:我发现了一个名为persianJS的 package 支持这种转换,但它不能在TypeScript中导入,我试过:

import * as persianjs from 'persianjs';

But error says:但是错误说:

Could not find a declaration file for module 'persianjs'. 'd:/Dev/front-end/Dis-dashboard/node_modules/persianjs/persian.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/persianjs` if it exists or add a new declaration (.d.ts) file containing `declare module 'persianjs';`

But there's no @types/persianjs .但是没有@types/persianjs

Is there any package or function that can be used in Angular? Angular中是否有可以使用的package或function?

Ignore the warning by putting // @ts-ignore above your import.通过将 // @ts-ignore 放在您的导入上方来忽略警告。 It's either that or create the type declaration files yourself.要么就是这样,要么自己创建类型声明文件。

Instead of persianJS I used persian-tools .我使用 persian -tools而不是persianJS first I installed with the command below:首先我使用以下命令安装:

npm install --save @persian-tools/persian-tools

Then I imported this package to my target file:然后我将此 package 导入到我的目标文件中:

import * as persianTools from '@persian-tools/persian-tools';

And used it like this:并像这样使用它:

persianTools.numberToWords("1372") // returns "صد و بیست و سه هزار و دویست"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM