Numerus는 정수를 로마 숫자로 변환하고 그 반대로 변환하는 확장 기능을 제공하는 Dart 패키지입니다. 정수 및 문자열 유형에 직접 직관적인 메서드를 제공함으로써 로마 숫자 표현 작업을 간소화합니다. 교육용 앱, 역사 데이터 처리 또는 로마 숫자 형식이 필요한 모든 응용 프로그램에 적합합니다. 이 패키지는 Android, iOS, Web, macOS, Windows, Linux 등 모든 주요 플랫폼을 지원하여 광범위한 호환성을 보장합니다. 깔끔하고 최소한의 구문을 통해 수치 변환 작업 시 코드 가독성을 높이고 반복 코드를 줄입니다.
사용 사례
날짜를 로마 숫자로 변환하기
수 체계를 위한 교육 앱
역사적 문서 디지털화
로마 숫자 스타일로 장 번호 표시
로마 숫자를 사용한 게임 점수 추적
주요 기능
간단한 정수에서 로마자 변환
문자열에서 정수로의 파싱
Dart 확장 메서드
크로스 플랫폼 지원
최소 API 표면
강력한 오류 처리
적합한 대상
수학 도구를 개발하는 개발자
교육 소프트웨어
역사적 주제를 가진 앱
읽기 쉬운 숫자 형식이 필요한 프로젝트
간결한 문법을 선호하는 사용자
고려 사항
표준 로마 숫자만 처리합니다(일반적인 규칙을 초과하는 뺄셈 변형은 제외)
로마 숫자의 제한으로 인해 매우 큰 숫자(>3999)는 지원하지 않습니다
비라틴 문자 스크립트에 대한 현지화 지원 없음
잘못된 입력 문자열과 같은 에지 케이스에 대해 수동 검증이 필요합니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Numerus
Dart extensions for translating decimal numbers to Roman numerals and vice versa.
Negative numbers are not supported.
Functions will return null in place of generating nonsense.
Zero can be specified as an option to the RomanNumeralConfig.
"Common" Roman numeral format used in modern times (i.e. MDCLXVI) is
the default RomanNumeralConfig style. There are other styles: vinculum, apostrophus,
and a compact apostrophus that uses single Unicode characters instead
of tally marks. See the example below.
Examples
import'package:numerus/numerus.dart';
voidmain() {
/// 1) Nice and easy, default config is the "common" config.var n = 418;
print(n.toRomanNumeralString());
// 'CDXVIII'var str = 'CDXVIII';
print(str.isValidRomanNumeralValue());
// trueprint(str.toRomanNumeralValue());
// 418/// 2) You can specify other [RomanNumeralConfig]'s to change the style./// You can set the config globally, if you'd like.RomanNumerals.romanNumeralsConfig = VinculumRomanNumeralsConfig();
/// 3) Vinculum config style
n = 3449671;
print(n.toRomanNumeralString());
// M̅M̅M̅C̅D̅X̅L̅MX̅DCLXXI
str = 'M̅M̅M̅C̅D̅X̅L̅MX̅DCLXXI';
print(str.isValidRomanNumeralValue());
// trueprint(str.toRomanNumeralValue());
// 3449671/// 4) You can specify the config inline, too./// 5) Apostrophus style
n = 2449671;
print(n.toRomanNumeralString(config: ApostrophusRomanNumeralsConfig()));
// CCCCIↃↃↃↃCCCCIↃↃↃↃCCCIↃↃↃIↃↃↃↃCCIↃↃIↃↃↃCIↃCCIↃↃIↃCLXXI/// 6) ... but frankly, globally set is probably the most common use caseRomanNumerals.romanNumeralsConfig = ApostrophusRomanNumeralsConfig();
str = 'CCCCIↃↃↃↃCCCCIↃↃↃↃCCCIↃↃↃIↃↃↃↃCCIↃↃIↃↃↃCIↃCCIↃↃIↃCLXXI';
print(str.isValidRomanNumeralValue());
// trueprint(str.toRomanNumeralValue());
// 2449671/// 7) The compact Apostrophus style uses special Unicode characters/// just for these symbols.RomanNumerals.romanNumeralsConfig = CompactApostrophusRomanNumeralsConfig();
n = 347449;
print(n.toRomanNumeralString());
// ↈↈↈↂↇↁↀↀCCCCXLIX// NOTE: if you see missing characters in this example, then you'll need to// install a font that supports them.
str = 'ↈↈↈↂↇↁↀↀCCCCXLIX';
print(str.isValidRomanNumeralValue());
// trueprint(str.toRomanNumeralValue());
// 347449/// 8) You can specify a "nulla" (zero placeholder) if you want/// to support zero easily.RomanNumerals.romanNumeralsConfig = CommonRomanNumeralsConfig(nulla: 'N');
n = 0;
print(n.toRomanNumeralString());
// N
str = 'N';
print(str.isValidRomanNumeralValue());
// trueprint(str.toRomanNumeralValue());
// 0
}
Features and bugs
Please file feature requests and bugs at the issue tracker.
Local development
Set up an environment for local development
Install Dart or Flutter
Install the coverage tool
$ dart pub global activate coverage
Install lcov on your system.
e.g. macOS with brew:
$ brew install lcov
Generate code coverage from tests
$ ./bin/coverage-gen
# If you are on macOS and would like the report to immediately# open, then run the following (not suitable for automation):
$ ./bin/coverage-gen -i