Yoko.Tool
1.6.2.3
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
.NET Framework 4.7.2
This package targets .NET Framework 4.7.2. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Yoko.Tool --version 1.6.2.3
NuGet\Install-Package Yoko.Tool -Version 1.6.2.3
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.3" />
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.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Yoko.Tool, 1.6.2.3"
#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.3 // Install Yoko.Tool as a Cake Tool #tool nuget:?package=Yoko.Tool&version=1.6.2.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
[TOC]
# Yoko.Tool
懒人必备工具箱
using Yoko.Tool;
💎 一般常用操作拓展
// 值类型转换
.ToInt32()
.ToBool()
.ToLong()
.ToDouble()
.ToDecimal()
.ToFloat()
// 时间操作
.ToDateTime() // 字符串 转 时间
.ToStartTime() // DateTime转换成开始时间00:00:00
.ToEndTime() // DateTime转换成结束时间23:59:59
.ToUnixTime() // DateTime时间转Unix时间戳(默认精确到毫秒13位)
.ToUnixTimeS() // DateTime时间转Unix时间戳(默认精确到秒10位)
.ToLocalTime() // Unix时间戳转DateTime本地时间(yyyy/MM/dd hh:MM:ss)
.DateDiff() // 返回时间差(N小时前,N分钟前···)
.GetDiffTime() // 计算2个时间差(相差多少年月日时分秒)
.GetDaysOfMonth() // 本月有多少天
.GetWeekNameOfDay() // 返回当前日期的星期名称
//字符串操作
.SplitCsv() // 分割逗号的字符串为List[]、string[]
.SplitCsvToInt() // 分割逗号的字符串为int[]
.ToIntList() // string数组转int数组
.ToFilterStr() // 过滤字符串中的/n,/t,/r
.ToByteArray() // string转换成字节数组
.ToJson() // 将一个对象转为Json格式字符串
.ToDynamic() // 将Json转为一个动态类型(运行时解析)
.ToMask() // 字符串敏感信息掩码 (123***789)
.ToMaskEmail() // 邮箱敏感信息掩码 (123****@163.com)
//值计算
//除法计算 a/b
//type=1 浮点数,保留2位小数(四舍五入):12.34
//type=2 百分比:12.23%
//type=3 带有逗号分隔符,保留小数位数(四舍五入):2,500,000.00
//type=4 货币表示,保留2位小数(四舍五入):¥12.34
DividedBy()
💎 值判断
// 在范围?
/**
int num = 50;
if (num.IsInRange(100, 1000)) { }
string value = "a";
if (value.IsIn("a", "b", "c")) { }
*/
IsInRange()
IsInRange()
IsIn()
IsContainsIn()
IsNullOrEmpty() // 是null或"" ?
IsValuable() // 有值?(与IsNullOrEmpty相反)
IsZero() // 是零?
IsInt() // 是Int?
IsNoInt() // 不是Int?
IsMoney() // 是金钱?
IsDate() // 是时间?
IsDate() // 是邮箱?
IsMobile() // 是手机号?(弱验证)
IsPhoneNumber() // 是手机号?(强验证)
IsTelephone() // 是座机?
IsIDcard() // 是身份证?
IsFax() // 是传真?
IsMatch() // 是适合正则匹配?
IsTrue() // 是true?
IsFalse() // 是false?
💎 随机数
// 按照年月时分秒随机数生成的文件名
YokoRandom.GetFileRndName()
// 生成随机数字
YokoRandom.GetFormatedNumeric(1, 100)
// 生成随机汉字
YokoRandom.GetRandChinese(6)
// 根据指定的样式生成:"?"代表一个字符,"#"代表一个一位数字,"*"代表一个字符串或一个一位数字
YokoRandom.GetRandStringByPattern(@"##??*")
// 获取指定长度的纯字母随机字符串
YokoRandom.GetRandWord(10)
// 获取指定长度的随机字符串
YokoRandom.GetRandomString(10)
💎 一般密码加解密/验证
// MD5 加密、加盐
"123456".ToMD5()
"123456".ToMD5("abc123")
// 两次加密、加盐
"123456".ToMD5Double()
"123456".ToMD5Double("abc123")
// AES加密、解密(密钥)
"123456".ToAES()
"123456".ToAESDecrypt()
// DES加密、解密(密钥)
"123456".ToDES()
"123456".ToDESDecrypt()
// RSA加密、解密
RsaKey rsaKey = RsaCrypt.GenerateRsaKeys(); //生成RSA密钥对
string encrypt = "123456".RSAEncrypt(rsaKey.PublicKey); //公钥加密
string s = encrypt.RSADecrypt(rsaKey.PrivateKey);//私钥解密
// 用于生成一般账号的加密密码
// 默认MD5+哈希。生成密码组成: 标识头 + 迭代 + 哈希大小 + salt值 + 哈希值
// 设置标识头Key:YokoPassWord.Key = "yoko";
// 值表现为 : yoko:64000:18:salt值:哈希值
"123456".ToPassWord("要MD5加密?")
// 验证密码
"目标比对密码".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() // 通过Url获取到Image格式的文件
YokoFile.ImageToBase64() // 根据http图片路径获取图片并转换为base64格式字符串
// 图片绘制
// 在图片上绘制文字
YokoFile.DrawStringWord(new DrawStyle
{
SourcePath = sourcePath, // 底图画布的路径
TargetPath = targetPath, // 保存图像的目标路径
TextContent = "Hello \n WoCao", // 文字内容
FamilyName = "宋体", // 字体
FontSize = 15, // 文字大小
Color = Color.White, // 颜色
X = 100, // 距左上角的 x 坐标
Y = 100, // 距左上角的 y 坐标
Width = 100, // 限定文本内容的宽
Height = 100 // 限定文本内容的高
});
🔍 图片文件操作 Yoko.Images.Webp 从静态路径或者网络路径转换、调整大小和压缩 jpeg、png 和 webp 图像
💎 时间段判断
🔍 判断是否在某个时间段内、是否包含某个时间段、两个时间段是否相交、连接两个时间段
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());
💎 雪花ID优化版
雪花算法实现方法有很多,它生成的ID更短、速度更快
可在单机或分布式环境生成数字型唯一ID,新增预留位,支持服务器时间回拨
兼容传统的经典雪花算法
🔍 调用示例
❄ NetCore/Net5 +
1、Startup.cs(ConfigureServices)
//全局初始化IdGenerator 只需全局一次(必须在第2步之前设置)
YokoId.SetIdGenerator(new IdGeneratorOptions(1));
2、生成ID
var newId = YokoId.NextId();
❄ NetFramework 4.7.2 +
1、Global.asax(Application_Start)
protected void Application_Start(Object sender, EventArgs e)
{
//全局初始化IdGenerator
YokoId.SetIdGenerator(new IdGeneratorOptions(1));
}
2、生成ID
var newId = YokoId.NextId();
🔍 参数设置
WorkerId,机器码,最重要参数,无默认值,必须 全局唯一,必须 程序设定,最大值63 特别提示:如果一台服务器部署多个独立服务,需要为每个服务指定不同的 WorkerId。
WorkerIdBitLength,机器码位长,决定 WorkerId 的最大值,默认值6,取值范围 [1, 19]
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 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.
-
.NETFramework 4.7.2
- Newtonsoft.Json (>= 13.0.1)
- SharpCompress (>= 0.30.1)
- System.Drawing.Common (>= 6.0.0)
-
.NETStandard 2.0
- Newtonsoft.Json (>= 13.0.1)
- SharpCompress (>= 0.30.1)
- System.Drawing.Common (>= 6.0.0)
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 |