FinnishPIDVerifier(芬兰PID验证器)

这个 Swift 库用于验证芬兰个人身份号码 (PID) 字符串(芬兰语: "henkilötunnus")。

芬兰 PID 是 ddmmyyAnnnX 格式的字符串,其中:

有关详细信息,请参阅 https://dvv.fi/henkilotunnus

用法

你可以在 example 子目录中找到如何使用此库的示例。

let verifier = FinnishPID.verify(pid: pid)
switch verifier.validity {
	case .validPID:
		print("PID is valid Finnish PID")
	case .invalidPID:
		print("PID is invalid Finnish PID")
	case .testPID:
		print("PID is valid test PID")
}
if verifier.isValid {
	print("PID is valid and not a test PID")
	print("PID is for a person born in \(verifier.dateString!)")
	print("Full date is \(verifier.birthDay!.formatted(date: .complete, time: .omitted))")
	print("Gender of the PID holder is \(verifier.genderString)")
	print("Date elements: day: \(verifier.day!) month: \(verifier.month!) year: \(verifier.year!)")
} else {
	print("PID is either test PID or invalid")
}

使用 PID 010101-123N 作为输入参数会打印

PID is valid Finnish PID
PID is valid and not a test PID
PID is for a person born in 1.1.1901
Full date is tiistaina 1. tammikuuta 1901
Gender of the PID holder is male
Date elements: day: 1 month: 1 year: 1901

返回的 verifier 结构体具有一些属性,你可以使用它们来查询验证结果

Valid PID 210911+0785: born: 21.9.1811, gender: female
Test PID: 211123A965F: born: 21.11.2023, gender: male

该库已针对芬兰语、瑞典语和英语进行了本地化。日期格式是固定的,但 genderStringdescription 会返回这些语言的字符串。

生成 PID

结构体 FinnishPIDGenerator 可用于生成有效和测试 PID。

请参阅生成器文档和 FiPIDGeneratorTests.swift 中的测试以获取详细信息。

测试

Tests 文件夹包含可用于测试实现的测试,包括生成的有效芬兰 PID 以及一些测试和无效 PID。

依赖项

依赖于 Swift Foundation。 使用 swift-docc-plugin 生成文档。

在你的项目中使用

使用此仓库的 URL 在你的 Package.swift 中将依赖项添加到此软件包

.package(url: "https://github.com/anttijuu/FinnishPIDVerifier.git", branch: "main"),

或者,使用 Xcode(File > Add Packages...)。

许可

版权所有 (c) 2023 Antti Juustila

特此授予任何人免费获得本软件及相关文档文件(“软件”)的副本的权利,允许对其进行不受限制的处理,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,并允许向其提供软件的人员按以下条件这样做

上述版权声明和本许可声明应包含在所有副本或软件的重要部分中。

本软件按“原样”提供,不作任何形式的明示或暗示的保证,包括但不限于适销性、适用于特定用途和不侵权的保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任承担责任,无论是在合同诉讼、侵权诉讼或其他诉讼中,因本软件或本软件的使用或其他处理而引起、由本软件或本软件的使用或其他处理而引起或与之相关的责任。