Yoko.Tool
1.5.0
See the version list below for details.
dotnet add package Yoko.Tool --version 1.5.0
NuGet\Install-Package Yoko.Tool -Version 1.5.0
<PackageReference Include="Yoko.Tool" Version="1.5.0" />
paket add Yoko.Tool --version 1.5.0
#r "nuget: Yoko.Tool, 1.5.0"
// Install Yoko.Tool as a Cake Addin #addin nuget:?package=Yoko.Tool&version=1.5.0 // Install Yoko.Tool as a Cake Tool #tool nuget:?package=Yoko.Tool&version=1.5.0
懒人必备工具箱
💎 主要功能
❄ 雪花Id优化版
❄ 值类型转换
❄ 哈希加密与验证
❄ 计算经纬度之间的距离
❄ 文件操作
❄ ·········
💎 使用方法
❄ 包管理器 Install-Package Yoko.Tool -Version 版本号
❄ .Net命令行 dotnet add package Yoko.Tool --version 版本号
💎 雪花ID
❄ 基于一般雪花算法,优化后生成的ID更短(15位起)、是整数(占用空间最多8字节)、速度更快。
❄ 新增预留位,支持服务器时间回拨。(比如服务器时间回拨1秒,也能自动适应生成临界时间的唯一ID)
💎 雪花参数设置
❄ WorkerIdBitLength,机器码位长,决定 WorkerId 的最大值,默认值6,取值范围 [1, 19],实际上有些语言采用 无符号 ushort (uint16) 类型接收该参数,所以最大值是16,如果是采用 有符号 short (int16),则最大值为15。
❄ WorkerId,机器码,最重要参数,无默认值,必须 全局唯一,必须 程序设定,缺省条件(WorkerIdBitLength取默认值)时最大值63,理论最大值 2^WorkerIdBitLength-1
特别提示:如果一台服务器部署多个独立服务,需要为每个服务指定不同的 WorkerId。
❄ SeqBitLength,序列数位长,默认值6,取值范围 [3, 21](建议不小于4),决定每毫秒基础生成的ID个数。规则要求:WorkerIdBitLength + SeqBitLength 不超过 22。
❄ MinSeqNumber,最小序列数,默认值5,取值范围 [5, MaxSeqNumber],每毫秒的前5个序列数对应编号0-4是保留位,其中1-4是时间回拨相应预留位,0是手工新值预留位。
❄ MaxSeqNumber,最大序列数,设置范围 [MinSeqNumber, 2^SeqBitLength-1],默认值0,真实最大序列数取最大值(2^SeqBitLength-1),不为0时,取其为真实最大序列数,一般无需设置,除非多机共享WorkerId分段生成ID(此时还要正确设置最小序列数)。
❄ BaseTime,基础时间(也称:基点时间、原点时间、纪元时间),有默认值(2021年),是毫秒时间戳(是整数,DatetTime类型),作用是:用生成ID时的系统时间与基础时间的差值(毫秒数)作为生成ID的时间戳。基础时间一般无需设置,如果觉得默认值太老,你可以重新设置,不过要注意,这个值以后最好不变。
💎 调用示例
1、全局初始化
NetCore/Net5,引用using Yoko.Tool;在Startup.cs(ConfigureServices)中全局注入
//全局初始化IdGenerator
YokoId.SetIdGenerator(new IdGeneratorOptions(1));
// 初始化过程只需全局一次,且必须在第2步之前设置。
2、生成ID
var newId = YokoId.NextId();
💎 值类型转换
🔍 string、decimal、double 转 int "目标".ToInt32()
🔍 string 转 bool ToBool
🔍 string 转 long ToLong
🔍 string、decimal、int 转 double ToDouble
🔍 string 、double、int 转 decimal ToDecimal
🔍 字符串 转 时间 ToDateTime
🔍 分割逗号的字符串为List[]、string[] SplitCsv
🔍 分割逗号的字符串为int[] SplitCsvToInt
🔍 string数组转int数组 ToIntList
🔍 过滤字符串中的/n,/t,/r ToJsonString
🔍 替换字符串中的"为',一般用于写入数据库的json ToDataBaseString
🔍 去除图片地址中的不正常字符\n、\ ToImgString
🔍 DateTime转换成开始时间00:00:00 ToStartTime
🔍 DateTime转换成结束时间23:59:59 ToEndTime
🔍 DateTime时间转Unix时间戳(默认精确到毫秒13位) ToUnixTime
🔍 DateTime时间转Unix时间戳(默认精确到秒10位) ToUnixTimeS
🔍 Unix时间戳转DateTime本地时间(yyyy/MM/dd hh:MM:ss) ToLocalTime
💎 哈希加密与验证
- 生成密码由5部分组成 💧 标识头:cadre 💧 迭代:64000 💧 哈希大小:18 💧 salt值 💧 哈希值
- 值常表现为
cadre:64000:18:salt值:哈希值
🔍 生成加密密码 Create(password,IsText);
🔍 验证密码 PassWordIsTrue(password,goodHash,IsText);
💎 根据经纬度计算两点间距离
GetDistance(x1,y1,x2,y2);
💎 文件操作
🔍 解压rar文件
UnRar();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 is compatible. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.1
- SharpCompress (>= 0.28.3)
-
.NETFramework 4.7.2
- SharpCompress (>= 0.28.3)
-
.NETFramework 4.8
- SharpCompress (>= 0.28.3)
-
.NETStandard 2.0
- SharpCompress (>= 0.28.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
3.0.0-beta.1 | 70 | 4/22/2024 | |
2.6.0-rc.3 | 100 | 12/14/2023 | |
2.6.0-rc.2 | 89 | 12/14/2023 | |
2.6.0-rc.1 | 97 | 12/14/2023 | |
2.5.4 | 180 | 5/22/2023 | |
2.5.3 | 272 | 2/24/2023 | |
2.5.2 | 436 | 9/7/2022 | |
2.5.1 | 383 | 9/7/2022 | |
2.5.0 | 398 | 9/5/2022 | |
2.4.4 | 412 | 8/5/2022 | |
2.4.3 | 418 | 8/2/2022 | |
2.4.2 | 410 | 7/27/2022 | |
2.4.1 | 398 | 7/25/2022 | |
2.4.0 | 439 | 7/11/2022 | |
2.2.0 | 439 | 6/20/2022 | |
2.1.1 | 412 | 6/14/2022 | |
2.1.0 | 439 | 5/7/2022 | |
2.0.0 | 420 | 4/29/2022 | |
1.6.3 | 442 | 6/14/2022 | |
1.6.2.8 | 451 | 4/29/2022 | |
1.6.2.7 | 471 | 4/21/2022 | |
1.6.2.6 | 437 | 3/17/2022 | |
1.6.2.4 | 321 | 12/17/2021 | |
1.6.2.3 | 312 | 12/13/2021 | |
1.6.2.2 | 294 | 12/2/2021 | |
1.6.2.1 | 361 | 11/15/2021 | |
1.6.2 | 345 | 11/2/2021 | |
1.6.1.1 | 375 | 10/25/2021 | |
1.6.1 | 342 | 10/22/2021 | |
1.6.0.1 | 361 | 9/24/2021 | |
1.6.0 | 343 | 9/17/2021 | |
1.5.8.1 | 347 | 9/15/2021 | |
1.5.7 | 539 | 9/10/2021 | |
1.5.6 | 392 | 9/10/2021 | |
1.5.5 | 369 | 9/9/2021 | |
1.5.4 | 365 | 9/5/2021 | |
1.5.3 | 344 | 9/3/2021 | |
1.5.2 | 334 | 9/3/2021 | |
1.5.1 | 346 | 9/3/2021 | |
1.5.0 | 336 | 9/2/2021 | |
1.4.3 | 352 | 9/2/2021 | |
1.4.2 | 327 | 9/2/2021 | |
1.4.1 | 319 | 9/2/2021 | |
1.4.0 | 356 | 8/24/2021 | |
1.3.0 | 348 | 8/24/2021 |