Yoko.Tool 1.6.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Yoko.Tool --version 1.6.2                
NuGet\Install-Package Yoko.Tool -Version 1.6.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Yoko.Tool" Version="1.6.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Yoko.Tool --version 1.6.2                
#r "nuget: Yoko.Tool, 1.6.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Yoko.Tool as a Cake Addin
#addin nuget:?package=Yoko.Tool&version=1.6.2

// Install Yoko.Tool as a Cake Tool
#tool nuget:?package=Yoko.Tool&version=1.6.2                

懒人必备工具箱

💎 雪花ID优化版

❄ 雪花算法实现方法有很多,本算法优化后生成的ID更短(15位+)、是整数(占用空间最多8字节)、速度更快

❄ 新增预留位,支持服务器时间回拨(比如服务器时间回拨1秒,也能自动适应生成临界时间的唯一ID)

❄ 新增数据中心ID:DataCenterId(机房ID,默认0,请确保全局唯一)。数据中心ID长度:DataCenterIdBitLength(默认0)

❄ 新增TimestampType,时间戳类型(0-毫秒,1-秒),默认0

💎 雪花参数设置

WorkerId,机器码,最重要参数,无默认值,必须 全局唯一,必须 程序设定,最大值63 特别提示:如果一台服务器部署多个独立服务,需要为每个服务指定不同的 WorkerId。

WorkerIdBitLength,机器码位长,决定 WorkerId 的最大值,默认值6,取值范围 [1, 19]

💎 调用示例(NetCore/Net5)

1、Startup.cs(ConfigureServices)

using Yoko.Tool;
//全局初始化IdGenerator 只需全局一次(必须在第2步之前设置)
YokoId.SetIdGenerator(new IdGeneratorOptions(1));

2、生成ID

var newId = YokoId.NextId();

💎 字符串拓展/效验:值类型转换、敏感信息掩码、效验、时间操作

🔍 object、string、decimal、double 转 int "123".ToInt32()

🔍 object、string 转 bool .ToBool()

🔍 object、string 转 long .ToLong()

🔍 object、string、decimal、int 转 double .ToDouble()

🔍 object、string 、double、int 转 decimal .ToDecimal()

🔍 object 转 float .ToFloat()

🔍 字符串 转 时间 .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();

🔍 转换成字节数组 .ToByteArray();

🔍 将一个对象转为Json格式字符串 .ToJson();

🔍 将Json转为一个动态类型(运行时解析) .ToDynamic();

🔍 普通字符串敏感信息掩码 .ToMask();

🔍 邮箱敏感信息掩码 .ToMaskEmail();

🔍 本月有多少天 GetDaysOfMonth()

🔍 返回当前日期的星期名称 GetWeekNameOfDay()

🔍 返回时间差(N小时前,N分钟前···) DateDiff()

🔍 计算2个时间差(相差多少年月日时分秒) GetDiffTime()


💎 值判断

🔍 在范围? IsInRange 、 IsInRange 、 IsIn 、IsContainsIn

int num = 50;
if (num.IsInRange(100, 1000)) { }

string value = "a";
if (value.IsIn("a", "b", "c")) { }

🔍 是null或""? IsNullOrEmpty

🔍 有值?(与IsNullOrEmpty相反) IsValuable

🔍 是零? IsZero

🔍 是Int? IsInt

🔍 不是Int? IsNoInt

🔍 是金钱? IsMoney

🔍 是时间? IsDate

🔍 是邮箱? IsDate

🔍 是手机号? IsMobile 、 IsPhoneNumber 、

🔍 是座机? IsTelephone

🔍 是身份证? IsIDcard

🔍 是传真? IsFax

🔍 是适合正则匹配? IsMatch

🔍 是true?false? IsTrue 、 IsFalse


💎 随机数

🔍 按照年月时分秒随机数生成的文件名 YokoRandom.GetFileRndName();

🔍 生成随机数字 YokoRandom.GetFormatedNumeric(1, 100);

🔍 生成随机汉字 YokoRandom.GetRandChinese(6);

🔍 根据指定的样式生成:"?"代表一个字符,"#"代表一个一位数字,"*"代表一个字符串或一个一位数字 YokoRandom.GetRandStringByPattern(@"##??*");

🔍 获取指定长度的纯字母随机字符串 YokoRandom.GetRandWord(10);

🔍 获取指定长度的随机字符串 YokoRandom.GetRandomString(10);


💎 一般密码加密解密、验证

🔍 MD5加、加盐 "123456".ToMD5(); "123456".ToMD5("yoko123");

🔍 MD5两次加密、加盐 "123456".ToMD5Double(); "123456".ToMD5Double("yoko123");

🔍 AES加密、解密(密钥) "123456".ToAES(); "123456".ToAESDecrypt();

🔍 DES加密、解密(密钥) "123456".ToDES(); "123456".ToDESDecrypt();

🔍 RSA加密、解密

//生成RSA密钥对
RsaKey rsaKey = RsaCrypt.GenerateRsaKeys();
//公钥加密
string encrypt = "123456".RSAEncrypt(rsaKey.PublicKey);
//私钥解密
string s = encrypt.RSADecrypt(rsaKey.PrivateKey);

🔍 生成加密密码 "123456".ToPassWord("要MD5加密?");


* 默认MD5+哈希。生成密码组成: 标识头 + 迭代 + 哈希大小 + salt值 + 哈希值

* 设置标识头Key:YokoPassWord.Key = "yoko";
* 值表现为 : yoko:64000:18:salt值:哈希值 

🔍 验证密码 "目标比对密码".IsTrue("输入的密码");

💎 经纬度操作

//根据经纬度计算两点间距离
YokoLngLat.GetDistance(x1,y1,x2,y2);
//坐标系互转
YokoLngLat.GPSToAMap();//GPS转高德(WGS84 --> GCJ-02)
YokoLngLat.AMapToGPS();//高德转GPS(GCJ-02 --> WGS84)
YokoLngLat.AMapToBMap();//高德转百度(GCJ-02 --> BD-09)
YokoLngLat.BMapToAMap();//百度转高德(BD-09 --> GCJ-02)

💎 文件操作

🔍 解压rar文件 YokoFile.UnRar('rar文件','解压到哪?')

🔍 http图片操作 YokoFile.UrlToImage() 、YokoFile.ImageToBase64()

💎 时间段判断

🔍 判断是否在某个时间段内、是否包含某个时间段、两个时间段是否相交、连接两个时间段

var range = new DateTimeRange("2021-9-3", "2021-9-5".ToDateTime());

//连接两个时间段,结果:2021-9-3~2021-9-6
range.Union("2021-9-4".ToDateTime(), "2021-9-6".ToDateTime()); 

//判断是否在某个时间段内,true
range.In("2021-9-3".ToDateTime(), "2021-9-6".ToDateTime());

//两个时间段是否相交,(true,2021-9-3~2021-9-4)
var (intersected,range2) = range.Intersect("2021-9-4".ToDateTime(), "2021-9-6".ToDateTime());

//判断是否包含某个时间段,true
range.Contains("2021-9-3".ToDateTime(), "2021-9-4".ToDateTime());
Product 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 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 71 4/22/2024
2.6.0-rc.3 101 12/14/2023 2.6.0-rc.3 is deprecated because it is no longer maintained.
2.6.0-rc.2 90 12/14/2023 2.6.0-rc.2 is deprecated because it is no longer maintained.
2.6.0-rc.1 98 12/14/2023 2.6.0-rc.1 is deprecated because it is no longer maintained.
2.5.4 182 5/22/2023
2.5.3 273 2/24/2023
2.5.2 437 9/7/2022
2.5.1 384 9/7/2022
2.5.0 399 9/5/2022
2.4.4 413 8/5/2022
2.4.3 419 8/2/2022
2.4.2 411 7/27/2022
2.4.1 401 7/25/2022
2.4.0 442 7/11/2022
2.2.0 440 6/20/2022
2.1.1 413 6/14/2022
2.1.0 440 5/7/2022
2.0.0 421 4/29/2022
1.6.3 443 6/14/2022
1.6.2.8 452 4/29/2022
1.6.2.7 472 4/21/2022
1.6.2.6 438 3/17/2022
1.6.2.4 322 12/17/2021
1.6.2.3 315 12/13/2021
1.6.2.2 295 12/2/2021
1.6.2.1 362 11/15/2021
1.6.2 346 11/2/2021
1.6.1.1 376 10/25/2021
1.6.1 343 10/22/2021
1.6.0.1 362 9/24/2021
1.6.0 344 9/17/2021
1.5.8.1 348 9/15/2021
1.5.7 540 9/10/2021
1.5.6 393 9/10/2021
1.5.5 370 9/9/2021
1.5.4 366 9/5/2021
1.5.3 345 9/3/2021
1.5.2 335 9/3/2021
1.5.1 347 9/3/2021
1.5.0 337 9/2/2021
1.4.3 353 9/2/2021
1.4.2 328 9/2/2021
1.4.1 320 9/2/2021
1.4.0 357 8/24/2021
1.3.0 349 8/24/2021