{"id":15478183,"url":"https://github.com/sky24n/common_utils","last_synced_at":"2025-05-15T10:06:02.261Z","repository":{"id":39176227,"uuid":"148185610","full_name":"Sky24n/common_utils","owner":"Sky24n","description":"Dart common utils library. DateUtil, EncryptUtil, JsonUtil, LogUtil, MoneyUtil, NumUtil, ObjectUtil,  RegexUtil, TextUtil, TimelineUtil, TimerUtil. 包含日期，正则，倒计时，时间轴等工具类。","archived":false,"fork":false,"pushed_at":"2023-01-09T15:02:18.000Z","size":460,"stargazers_count":1440,"open_issues_count":14,"forks_count":265,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-05-15T10:05:04.075Z","etag":null,"topics":["dart","dart-package","dateutil","endecodeutil","flutter","logutil","moneyutil","numutil","objectutil","regexutil","textutil","timelineutil","timerutil"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Sky24n.png","metadata":{"files":{"readme":"README-EN.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://sky24n.github.io/Sky24n/image/ali_pay.jpg","https://sky24n.github.io/Sky24n/image/wechat_pay.jpg"]}},"created_at":"2018-09-10T16:28:26.000Z","updated_at":"2025-05-14T07:09:19.000Z","dependencies_parsed_at":"2023-02-08T12:20:19.195Z","dependency_job_id":null,"html_url":"https://github.com/Sky24n/common_utils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sky24n%2Fcommon_utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sky24n%2Fcommon_utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sky24n%2Fcommon_utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sky24n%2Fcommon_utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sky24n","download_url":"https://codeload.github.com/Sky24n/common_utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319720,"owners_count":22051073,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","dart-package","dateutil","endecodeutil","flutter","logutil","moneyutil","numutil","objectutil","regexutil","textutil","timelineutil","timerutil"],"created_at":"2024-10-02T04:02:37.109Z","updated_at":"2025-05-15T10:05:57.224Z","avatar_url":"https://github.com/Sky24n.png","language":"Dart","funding_links":["https://sky24n.github.io/Sky24n/image/ali_pay.jpg","https://sky24n.github.io/Sky24n/image/wechat_pay.jpg"],"categories":[],"sub_categories":[],"readme":"Language: English | [中文简体](https://github.com/Sky24n/common_utils)\n\n[![Pub](https://img.shields.io/pub/v/common_utils.svg?style=flat-square\u0026color=009688)](https://pub.dartlang.org/packages/common_utils)\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;[![Pub](https://img.shields.io/pub/v/common_utils.svg?style=flat-square\u0026color=2196F3)](https://pub.flutter-io.cn/packages/common_utils)\n\n## common_utils is a Dart common utils library.\n\n1、Dart project dependencies.\n```yaml\ndependencies:\n  common_utils: ^2.1.0\n```\n2、Dart project dependencies, [flustars][flustars_github] is a Flutter common utils library. More SpUtil, ScreenUtil, DirectoryUtil.\n```yaml\ndependencies:\n  flustars: ^2.0.1  \n```\n\nDart utils Library [common_utils][common_utils_github]\n1. TimelineUtil     : timeline util.\n2. TimerUtil        : countdown，timer.\n3. MoneyUtil        : fen to yuan, format output.\n4. LogUtil          : simply encapsulate print logs.\n5. DateUtil         : date conversion formatted output.\n6. RegexUtil        : regular verification of mobile phone numbers, ID cards, mailboxes and so on.\n7. NumUtil          : keep [x] decimal places, add subtract multiply divide without loosing precision.\n8. ObjectUtil       : object is empty, two List is equal.\n9. EncryptUtil      : xor, md5 ，Base64..\n10. TextUtil        : hide phoneNo.\n11. JsonUtil        : json to object.\n\nFlutter utils Library [flustars][flustars_github]\n1. SpUtil           : SharedPreferences Util.\n2. ScreenUtil       : get screen width height density, appBarHeight, statusBarHeight, orientation.\n3. WidgetUtil       : get Widget width height，coordinates.\n4. ImageUtil        : get image size.\n5. DirectoryUtil    : Directory Util.\n6. DioUtil          : Dio Util(move to[DioUtil](https://github.com/Sky24n/FlutterRepos/blob/master/base_library/lib/src/data/net/dio_util.dart))。\n\n### APIs\n* SpUtil\nSharedPreferences util.\n```dart\n/// await sp initialized。\nawait SpUtil.getInstance();  \n  \n/// support default value.\nString name = SpUtil.putString(\"key_username\", \"Sky24n\");\nbool isShow = SpUtil.getBool(\"key_show\", defValue: true);\n  \n/// save object example.\nCity city = new City();\ncity.name = \"成都市\";\nSpUtil.putObject(\"loc_city\", city);\n    \nCity hisCity = SpUtil.getObj(\"loc_city\", (v) =\u003e City.fromJson(v));\nprint(\"City: \" + (hisCity == null ? \"null\" : hisCit.toString()));\n  \n\n/// save object list example.\nList\u003cCity\u003e list = new List();\nlist.add(new City(name: \"成都市\"));\nlist.add(new City(name: \"北京市\"));\nSpUtil.putObjectList(\"loc_city_list\", list);\n    \nList\u003cCity\u003e _cityList = SpUtil.getObjList(\"loc_city_list\", (v) =\u003e City.fromJson(v));\nprint(\"City list: \" + (_cityList == null ? \"null\" : _cityList.toString()));\n```\n\n* DateUtil -\u003e [Example](https://github.com/Sky24n/flutter_wanandroid/blob/master/lib/demos/date_page.dart)\n```\n/// common format。example：\"yyyy/MM/dd HH:mm:ss\"，\"yyyy/M/d HH:mm:ss\"。\n/// year -\u003e yyyy/yy   month -\u003e MM/M    day -\u003e dd/d\n/// hour -\u003e HH/H      minute -\u003e mm/m   second -\u003e ss/s\nclass DataFormats {\n  static String full = \"yyyy-MM-dd HH:mm:ss\";\n  static String y_mo_d_h_m = \"yyyy-MM-dd HH:mm\";\n  static String y_mo_d = \"yyyy-MM-dd\";\n  static String y_mo = \"yyyy-MM\";\n  static String mo_d = \"MM-dd\";\n  static String mo_d_h_m = \"MM-dd HH:mm\";\n  static String h_m_s = \"HH:mm:ss\";\n  static String h_m = \"HH:mm\";\n\n  static String zh_full = \"yyyy年MM月dd日 HH时mm分ss秒\";\n  static String zh_y_mo_d_h_m = \"yyyy年MM月dd日 HH时mm分\";\n  static String zh_y_mo_d = \"yyyy年MM月dd日\";\n  static String zh_y_mo = \"yyyy年MM月\";\n  static String zh_mo_d = \"MM月dd日\";\n  static String zh_mo_d_h_m = \"MM月dd日 HH时mm分\";\n  static String zh_h_m_s = \"HH时mm分ss秒\";\n  static String zh_h_m = \"HH时mm分\";\n}\n\ngetDateTimeByMs                 : \ngetDateMsByTimeStr              : \ngetNowDateMs                    : get Now Date milliseconds.\ngetNowDateStr                   : get Now DateStr.(yyyy-MM-dd HH:mm:ss)\nformatDate                      : format Date by DateTime.\nformatDateStr                   : format Date by DateStr.\nformatDateMs                    : format Date by milliseconds.\ngetWeekday                      : get weekDay.\ngetDayOfYear                    : get day of year.\nisToday                         : is today.\nisYesterday                     : is yesterday.\nisWeek                          : is week.\nyearIsEqual                     : whether it is leap year.\nisLeapYear                      : year is equal.\n\n// example\nDateUtil.formatDateMs(dateMs, format: DateFormats.full); //2019-07-09 16:16:16\nDateUtil.formatDateStr('2019-07-09 16:16:16', format: \"yyyy/M/d HH:mm:ss\"); //2019/7/9 16:16:16\nDateUtil.formatDate(DateTime.now(), format: DateFormats.zh_full); //2019年07月09日 16时16分16秒\n```\n\n* EncryptUtil\n```\nencodeMd5                   : md5.\nencodeBase64                : Base64 encode.\ndecodeBase64()              : Base64 decode.\nxorCode()                   : xor.\nxorBase64Encode()           : xor Base64 encode.\nxorBase64Decode()           : xor Base64 decode.\n\nconst String key = '11, 22, 33, 44, 55, 66';\nString userName = 'Sky24n';\nString encode = EncryptUtil.xorBase64Encode(userName, key); // WH1YHgMs\nString decode = EncryptUtil.xorBase64Decode(encode, key); // Sky24n\n```\n\n* JsonUtil\n```\nencodeObj                   : Obj to json string.\ngetObj                      : json string to object.\ngetObject                   : json string / map to object.\ngetObjList                  : json string list to object list.\ngetObjectList               : json string / map list to object list.\n\nString objStr = \"{\\\"name\\\":\\\"成都市\\\"}\";\nCity hisCity = JsonUtil.getObj(objStr, (v) =\u003e City.fromJson(v));\nString listStr = \"[{\\\"name\\\":\\\"成都市\\\"}, {\\\"name\\\":\\\"北京市\\\"}]\";\nList\u003cCity\u003e cityList = JsonUtil.getObjList(listStr, (v) =\u003e City.fromJson(v));\n```\n\n* LogUtil\n```\ninit(tag, isDebug, maxLen)  : tag, isDebug, maxLen.\ne(object, tag)              : Log e.\nv(object, tag)              : Log v,debug output.\n\n//超长log查看\ncommon_utils e  — — — — — — — — — — — — — — — — st — — — — — — — — — — — — — — — —\ncommon_utils e | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,\ncommon_utils e | 7,988,989,990,991,992,993,994,995,996,997,998,999,\ncommon_utils e  — — — — — — — — — — — — — — — — ed — — — — — — — — — — — — — — — —\n```\n\n* MoneyUtil -\u003e [Example](https://github.com/Sky24n/flutter_wanandroid/blob/master/lib/demos/money_page.dart)\n```\nchangeF2Y                   : fen to yuan, format output.\nchangeFStr2YWithUnit        : fen str to yuan, format \u0026 unit  output.\nchangeF2YWithUnit           : fen to yuan, format \u0026 unit  output.\nchangeYWithUnit             : yuan, format \u0026 unit  output.(yuan is int,double,str).\nchangeY2F                   : fen to yuan.\n```\n\n* NumUtil -\u003e [Example](https://github.com/Sky24n/flutter_wanandroid/blob/master/lib/demos/num_util_page.dart)\n```\ngetIntByValueStr            : get int By value string.\ngetDoubleByValueStr         : get double By value string.\ngetNumByValueStr            : Keep [x] decimal places by value string.\ngetNumByValueDouble         : Keep [x] decimal places by double.\nisZero                      : is Zero.\nadd                         : add (without loosing precision).\nsubtract                    : subtract (without loosing precision).\nmultiply                    : multiply (without loosing precision).\ndivide                      : divide (without loosing precision).\nremainder                   : 余.\nlessThan                    : \u003c .\nthanOrEqual                 : \u003c= .\ngreaterThan                 : \u003e .\ngreaterOrEqual              : \u003e= .\n```\n\n* ObjectUtil -\u003e [Example](https://github.com/Sky24n/flutter_wanandroid/blob/master/lib/demos/object_util_page.dart)\n```\nisEmptyString             : String is empty.\nisEmptyList               : List is empty.\nisEmptyMap                : Map Map empty.\nisEmpty                   : Object is empty.(String List Map).\nisNotEmpty                : Object is not empty.(String List Map).\ntwoListIsEqual            : Two List Is Equal.\n```\n\n* RegexUtil -\u003e [Example](https://github.com/Sky24n/flutter_wanandroid/blob/master/lib/demos/regex_page.dart)\n```\nisMobileSimple            : \nisMobileExact             : \nisTel                     : \nisIDCard                  : \nisIDCard15                : \nisIDCard18                : \nisIDCard18Exact           : \nisEmail                   : \nisURL                     : \nisZh                      : \nisDate                    : \nisIP                      : \nisUserName                :\nisQQ                      :\n```\n\n* TextUtil\n```\nisEmpty                     : isEmpty.\nformatSpace4                : format Space 4.\nformatComma3                : format Comma 3.\nformatDoubleComma3          : format Double Comma3.\nhideNumber                  : hide number.\nreplace                     : replace.\nsplit                       : split.\nreverse                     : reverse.\n  \n/// example\nString phoneNo = TextUtil.formatSpace4(\"15845678910\"); // 1584 5678 910\nString num     = TextUtil.formatComma3(\"1234\"); // 123,4\nString phoneNo = TextUtil.hideNumber(\"15845678910\")// 158****8910\n```\n\n* TimelineUtil -\u003e [Example](https://github.com/Sky24n/flutter_wanandroid/blob/master/lib/demos/timeline_page.dart)\n```\n///(xx)Configurable output.\nenum DayFormat {\n  ///(less than 30s-\u003ejust now)、x minutes、x hours、(Yesterday)、x days.\n  Simple,\n  ///(less than 30s-\u003ejust now)、x minutes、x hours、[This year:(Yesterday/a day ago)、(two days age)、MM-dd ]、[past years: yyyy-MM-dd]\n  Common,\n  ///(less than 30s-\u003ejust now)、x minutes、x hours、[This year:(Yesterday HH:mm/a day ago)、(two days age)、MM-dd HH:mm]、[past years: yyyy-MM-dd HH:mm]\n  Full,\n}\n///Timeline information configuration.\nabstract class TimelineInfo {\n  String suffixAgo(); //suffix ago(后缀 后).\n  String suffixAfter(); //suffix after(后缀 前).\n  int maxJustNowSecond() =\u003e 30; // max just now second.\n  String lessThanOneMinute() =\u003e ''; //just now(刚刚).\n  String customYesterday() =\u003e ''; //Yesterday(昨天).优先级高于keepOneDay\n  bool keepOneDay(); //保持1天,example: true -\u003e 1天前, false -\u003e MM-dd.\n  bool keepTwoDays(); //保持2天,example: true -\u003e 2天前, false -\u003e MM-dd.\n  String oneMinute(int minutes); //a minute(1分钟).\n  String minutes(int minutes); //x minutes(x分钟).\n  String anHour(int hours); //an hour(1小时).\n  String hours(int hours); //x hours(x小时).\n  String oneDay(int days); //a day(1天).\n  String days(int days); //x days(x天).\n}\nsetLocaleInfo               : add custom configuration.\nformatByDateTime            : timeline format output by DateTime .\nformat                      : timeline format output.\nformatA                     : timeline format output. like QQ.\n\n```\n\n* TimerUtil -\u003e [Example](https://github.com/Sky24n/flutter_wanandroid/blob/master/lib/demos/timer_page.dart)\n```\nsetInterval                 : set Timer interval.\nsetTotalTime                : set countdown totalTime.\nstartTimer()                : start Timer.\nstartCountDown              : start countdown Timer.\nupdateTotalTime             : update countdown totalTime.\ncancel                      : cancels the timer.\nsetOnTimerTickCallback      : set timer callback.\nisActive                    : timer is Active.\n```\n\n### [Flutter Demos](https://github.com/Sky24n/flutter_wanandroid/tree/master/lib/demos)\n\n\u003e- |--demos\n\u003e    - |-- city_select_page.dart\n\u003e    - |-- date_page.dart\n\u003e    - |-- image_size_page.dart\n\u003e    - |-- money_page.dart\n\u003e    - |-- pinyin_page.dart\n\u003e    - |-- regex_page.dart\n\u003e    - |-- round_portrait_page.dart\n\u003e    - |-- timeline_page.dart\n\u003e    - |-- timer_page.dart\n\u003e    - |-- widget_page.dart\n\n### Demo Apk : [flutter_wanandroid](https://github.com/Sky24n/Doc)\n\n### Thanks\nBlankj [AndroidUtilCode](https://github.com/Blankj/AndroidUtilCode)。  \nAndres Araujo [timeago](https://github.com/andresaraujo/timeago.dart)。  \na14n [decimal](https://github.com/a14n/dart-decimal)。\n\n### Apps\n[flutter_wanandroid](https://github.com/Sky24n/flutter_wanandroid)  \n[Moss App](https://github.com/Sky24n/Moss)\n\n### [Change Log](CHANGELOG.md)\nv1.2.1 (2020.05.29)  \n1、fix DataFormats -\u003e DateFormats。  \n2、fix TimelineInfo bugs。\n\n\n\n[flustars_github]: https://github.com/Sky24n/flustars\n[common_utils_github]: https://github.com/Sky24n/common_utils","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsky24n%2Fcommon_utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsky24n%2Fcommon_utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsky24n%2Fcommon_utils/lists"}