* Validates the digit mapping value. * @param {Chain} value Value to be validated * @param {Field} setting Sender field * @return {boolean|object}
(value, setting)
| 476 | * @return {boolean|object} |
| 477 | */ |
| 478 | validateDigitMappingValue (value, setting) { |
| 479 | // Can't validate digit mapping without valid basic range |
| 480 | if (!this.isSettingValid('basicRangeStart', 'basicRangeEnd')) { |
| 481 | return false |
| 482 | } |
| 483 | |
| 484 | const basicRangeStart = this.getSettingValue('basicRangeStart') |
| 485 | const basicRangeEnd = this.getSettingValue('basicRangeEnd') |
| 486 | |
| 487 | const invalidIndex = value.getCodePoints().findIndex(codePoint => |
| 488 | codePoint < basicRangeStart || codePoint > basicRangeEnd) |
| 489 | |
| 490 | if (invalidIndex !== -1) { |
| 491 | return { |
| 492 | key: 'bootstringDigitMappingInvalid', |
| 493 | message: |
| 494 | `Character at index ${invalidIndex} needs to be part of the given ` + |
| 495 | 'basic code point range' |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | return true |
| 500 | } |
| 501 | |
| 502 | /** |
| 503 | * Validates the delimiter value. |
nothing calls this directly
no test coverage detected