Get the name of a number, even if it's stupidly big.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
此仓库已存档。您可以查看文件和克隆,但不能推送或创建工单/合并请求。

46 行
1.2 KiB

  1. import { Transform } from 'stream'
  2. import NumberSystem from './NumberSystem'
  3. import { ReadStreamOptions } from './common'
  4. export default class ConverterStream extends Transform {
  5. private thousandPower: number = 0
  6. constructor(private readonly system: NumberSystem, private readonly options: ReadStreamOptions) {
  7. super()
  8. this.thousandPower = 0
  9. }
  10. _transform(chunk: any, _encoding: BufferEncoding, callback: Function) {
  11. const { scale, encoding } = this.options
  12. const [ones = 0, tens = 0, hundreds = 0] = chunk
  13. .toString(encoding!)
  14. .split('')
  15. .filter((s: string) => /[0-9]/.test(s))
  16. .map((d: string) => Number(d)) // todo use encoding
  17. if (!(ones === 0 && tens === 0 && hundreds === 0)) {
  18. if (this.thousandPower > 0) {
  19. this.push(
  20. this.system.getKiloName[scale!]!(this.thousandPower)
  21. .split('')
  22. .reverse()
  23. .join(''),
  24. )
  25. this.push(' ')
  26. }
  27. this.push(
  28. this.system
  29. .getKiloCount(hundreds, tens, ones)
  30. .split('')
  31. .reverse()
  32. .join(''),
  33. )
  34. this.push(' ')
  35. }
  36. this.thousandPower = this.thousandPower + 1
  37. callback()
  38. }
  39. }