Awesome
<div align=center> <img src="./logo.png" width="200" height="200"/> <br/> </div> <div STYLE="page-break-after: always;"></div> <p style="font-size: 20px"> Lancet is a comprehensive, efficient, and reusable util function library of go. Inspired by the java apache common package and lodash.js. </p><a href="https://www.golancet.cn/en/" target="_blank"> Website</a> | ็ฎไฝไธญๆ
Features
- ๐ Comprehensive, efficient and reusable.
- ๐ช 700+ go util functions, support string, slice, datetime, net, crypt...
- ๐ Only depends on two kinds of libraries: go standard library and golang.org/x.
- ๐ Unit test for every exported function.
Installation
Note:
- <b>For users who use go1.18 and above, it is recommended to install lancet v2.x.x. Cause in v2.x.x all functions were rewritten with generics of go1.18.</b>
go get github.com/duke-git/lancet/v2 // will install latest version of v2.x.x
- <b>For users who use version below go1.18, you should install v1.x.x. The latest of v1.x.x is v1.4.4. </b>
go get github.com/duke-git/lancet // below go1.18, install latest version of v1.x.x
Usage
Lancet organizes the code into package structure, and you need to import the corresponding package name when use it. For example, if you use string-related functions,import the strutil package like below:
import "github.com/duke-git/lancet/v2/strutil"
Example
Here takes the string function Reverse (reverse order string) as an example, and the strutil package needs to be imported.
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/strutil"
)
func main() {
s := "hello"
rs := strutil.Reverse(s)
fmt.Println(rs) //olleh
}
Documentation
<span id="index">Index<span>
- Algorithm
- Compare
- Concurrency
- Condition
- Convertor
- Cryptor
- Datetime
- Datastructure
- Fileutil
- Formatter
- Function
- Maputil
- Mathutil
- Netutil
- Pointer
- Random
- Retry
- Slice
- Stream
- Structs
- Strutil
- System
- Tuple
- Validator
- Xerror
import "github.com/duke-git/lancet/v2/algorithm"
Function list:
- <big>BubbleSort</big> : sorts slice with bubble sort algorithm, will change the original slice. [doc] [play]
- <big>CountSort</big> : sorts slice with bubble sort algorithm, don't change original slice. [doc] [play]
- <big>HeapSort</big> : sorts slice with heap sort algorithm, will change the original slice. [doc] [play]
- <big>InsertionSort</big> : sorts slice with insertion sort algorithm, will change the original slice. [doc] [play]
- <big>MergeSort</big> : sorts slice with merge sort algorithm, will change the original slice. [doc] [play]
- <big>QuickSort</big> : sorts slice with quick sort algorithm, will change the original slice. [doc] [play]
- <big>SelectionSort</big> : sorts slice with selection sort algorithm, will change the original slice. [doc] [play]
- <big>ShellSort</big> : sorts slice with shell sort algorithm, will change the original slice. [doc] [play]
- <big>BinarySearch</big> : returns the index of target within a sorted slice, use binary search (recursive call itself). [doc] [play]
- <big>BinaryIterativeSearch</big> : returns the index of target within a sorted slice, use binary search (no recursive). [doc] [play]
- <big>LinearSearch</big> : returns the index of target in slice base on equal function. [doc] [play]
- <big>LRUCache</big> : implements memory cache with lru algorithm. [doc] [play]
import "github.com/duke-git/lancet/v2/compare"
Function list:
- <big>Equal</big> : Checks if two values are equal or not. (check both type and value) [doc] [play]
- <big>EqualValue</big> : Checks if two values are equal or not. (check value only) [doc] [play]
- <big>LessThan</big> : Checks if value
left
less than valueright
. [doc] [play] - <big>GreaterThan</big> : Checks if value
left
greater than valueright
. [doc] [play] - <big>LessOrEqual</big> : Checks if value
left
less than or equal than valueright
. [doc] [play] - <big>GreaterOrEqual</big> : Checks if value
left
less greater or equal than valueright
. [doc] [play] - <big>InDelta</big> : Checks if two values are equal or not within a delta. [doc]
import "github.com/duke-git/lancet/v2/concurrency"
Function list:
- <big>NewChannel</big> : create a Channel pointer instance. [doc] [play]
- <big>Bridge</big> : link multiply channels into one channel. [doc] [play]
- <big>FanIn</big> : merge multiple channels into one channel. [doc] [play]
- <big>Generate</big> : creates a channel, then put values into the channel. [doc] [play]
- <big>Or</big> : read one or more channels into one channel, will close when any readin channel is closed. [doc] [play]
- <big>OrDone</big> : read a channel into another channel, will close until cancel context. [doc] [play]
- <big>Repeat</big> : create channel, put values into the channel repeatedly until cancel the context. [doc] [play]
- <big>RepeatFn</big> : create a channel, executes fn repeatedly, and put the result into the channel, until close context. [doc] [play]
- <big>Take</big> : create a channel whose values are taken from another channel with limit number. [doc] [play]
- <big>Tee</big> : split one chanel into two channels, until cancel the context. [doc] [play]
import "github.com/duke-git/lancet/v2/condition"
Function list:
- <big>Bool</big> : returns the truthy value of anything. [doc] [play]
- <big>And</big> : returns true if both a and b are truthy. [doc] [play]
- <big>Or</big> : returns false if neither a nor b is truthy. [doc] [play]
- <big>Xor</big> : returns true if a or b but not both is truthy. [doc] [play]
- <big>Nor</big> : returns true if neither a nor b is truthy. [doc] [play]
- <big>Xnor</big> : returns true if both a and b or neither a nor b are truthy. [doc] [play]
- <big>Nand</big> : returns false if both a and b are truthy. [doc] [play]
- <big>TernaryOperator</big> : ternary operator. [doc] [play]
import "github.com/duke-git/lancet/v2/convertor"
Function list:
- <big>ColorHexToRGB</big> : convert color hex to color rgb. [doc] [play]
- <big>ColorRGBToHex</big> : convert rgb color to hex color. [doc] [play]
- <big>ToBool</big> : convert string to bool. [doc] [play]
- <big>ToBytes</big> : convert value to byte slice. [doc] [play]
- <big>ToChar</big> : convert string to char slice. [doc] [play]
- <big>ToChannel</big> : convert a collection of elements to a read-only channel. [doc] [play]
- <big>ToFloat</big> : convert value to float64, if param is a invalid floatable, will return 0.0 and error. [doc] [play]
- <big>ToInt</big> : convert value to int64 value, if input is not numerical, return 0 and error. [doc] [play]
- <big>ToJson</big> : convert value to a json string. [doc] [play]
- <big>ToMap</big> : convert a slice of structs to a map based on iteratee function. [doc] [play]
- <big>ToPointer</big> : return a pointer of passed value. [doc] [play]
- <big>ToString</big> : convert value to string. [doc] [play]
- <big>StructToMap</big> : convert struct to map, only convert exported struct field. [doc] [play]
- <big>MapToSlice</big> : convert map to slice based on iteratee function. [doc] [play]
- <big>EncodeByte</big> : encode data to byte slice. [doc] [play]
- <big>DecodeByte</big> : decode byte slice data to target object. [doc] [play]
- <big>DeepClone</big> : creates a deep copy of passed item, can't clone unexported field of struct. [doc] [play]
- <big>CopyProperties</big> : copies each field from the source struct into the destination struct. [doc] [play]
- <big>ToInterface</big> : converts reflect value to its interface type. [doc] [play]
- <big>Utf8ToGbk</big> : converts utf8 encoding data to GBK encoding data [doc] [play]
- <big>GbkToUtf8</big> : converts GBK encoding data to utf8 encoding data. [doc] [play]
- <big>ToStdBase64</big> : converts a value to a string encoded in standard Base64. [doc]
- <big>ToUrlBase64</big> : converts a value to a string encoded in url Base64. [doc]
- <big>ToRawStdBase64</big> : converts a value to a string encoded in raw standard Base64. [doc]
- <big>ToRawUrlBase64</big> : converts a value to a string encoded in raw url Base64. [doc]
import "github.com/duke-git/lancet/v2/cryptor"
Function list:
- <big>AesEcbEncrypt</big> : encrypt byte slice data with key use AES ECB algorithm. [doc] [play]
- <big>AesEcbDecrypt</big> : decrypt byte slice data with key use AES ECB algorithm. [doc] [play]
- <big>AesCbcEncrypt</big> : encrypt byte slice data with key use AES CBC algorithm. [doc] [play]
- <big>AesCbcDecrypt</big> : decrypt byte slice data with key use AES CBC algorithm. [doc] [play]
- <big>AesCtrCrypt</big> : encrypt/ decrypt byte slice data with key use AES CRC algorithm. [doc] [play]
- <big>AesCfbEncrypt</big> : encrypt byte slice data with key use AES CFB algorithm. [doc] [play]
- <big>AesCfbDecrypt</big> : decrypt byte slice data with key use AES CFB algorithm. [doc] [play]
- <big>AesOfbEncrypt</big> : encrypt byte slice data with key use AES OFB algorithm. [doc] [play]
- <big>AesOfbDecrypt</big> : decrypt byte slice data with key use AES OFB algorithm. [doc] [play]
- <big>AesGcmEncrypt</big> : encrypt byte slice data with key use AES GCM algorithm. [doc] [play]
- <big>AesGcmDecrypt</big> : decrypt byte slice data with key use AES GCM algorithm. [doc] [play]
- <big>Base64StdEncode</big> : encode string with base64 encoding. [doc] [play]
- <big>Base64StdDecode</big> : decode string with base64 encoding. [doc] [play]
- <big>DesEcbEncrypt</big> : encrypt byte slice data with key use DES ECB algorithm. [doc] [play]
- <big>DesEcbDecrypt</big> : decrypt byte slice data with key use DES ECB algorithm. [doc] [play]
- <big>DesCbcEncrypt</big> : encrypt byte slice data with key use DES CBC algorithm. [doc] [play]
- <big>DesCbcDecrypt</big> : decrypt byte slice data with key use DES CBC algorithm. [doc] [play]
- <big>DesCtrCrypt</big> : encrypt/decrypt byte slice data with key use DES CRY algorithm. [doc] [play]
- <big>DesCfbEncrypt</big> : encrypt byte slice data with key use DES CFB algorithm. [doc] [play]
- <big>DesCfbDecrypt</big> : decrypt byte slice data with key use DES CFB algorithm. [doc] [play]
- <big>DesOfbEncrypt</big> : encrypt byte slice data with key use DES OFB algorithm. [doc] [play]
- <big>DesOfbDecrypt</big> : decrypt byte slice data with key use DES OFB algorithm. [doc] [play]
- <big>HmacMd5</big> : return the md5 hmac hash of string. [doc] [play]
- <big>HmacMd5WithBase64</big> : return the md5 hmac hash of base64 string. [doc]
- <big>HmacSha1</big> : return the hmac hash of string use sha1. [doc] [play]
- <big>HmacSha1WithBase64</big> : return the hmac hash of string use sha1 with base64. [doc] [play]
- <big>HmacSha256</big> : return the hmac hash of string use sha256. [doc] [play]
- <big>HmacSha256WithBase64</big> : return the hmac hash of string use sha256 with base64. [doc] [play]
- <big>HmacSha512</big> : return the hmac hash of string use sha512. [doc] [play]
- <big>HmacSha512WithBase64</big> : return the hmac hash of string use sha512 with base64. [doc] [play]
- <big>Md5Byte</big> : return the md5 string of byte slice. [doc] [play]
- <big>Md5ByteWithBase64</big> : return the md5 string of byte slice with base64. [doc] [play]
- <big>Md5String</big> : return the md5 value of string. [doc] [play]
- <big>Md5StringWithBase64</big> : return the md5 value of string with base64. [doc] [play]
- <big>Md5File</big> : return the md5 value of file. [doc]
- <big>Sha1</big> : return the sha1 value (SHA-1 hash algorithm) of base64 string. [doc] [play]
- <big>Sha1WithBase64</big> : return the sha1 value (SHA-1 hash algorithm) of string. [doc] [play]
- <big>Sha256</big> : return the sha256 value (SHA-256 hash algorithm) of string. [doc] [play]
- <big>Sha256WithBase64</big> : return the sha256 value (SHA256 hash algorithm) of base64 string. [doc] [play]
- <big>Sha512</big> : return the sha512 value (SHA-512 hash algorithm) of string. [doc] [play]
- <big>Sha512WithBase64</big> : return the sha512 value (SHA-512 hash algorithm) of base64 string. [doc] [play]
- <big>GenerateRsaKey</big> : create rsa private and public pemo file. [doc] [play]
- <big>RsaEncrypt</big> : encrypt data with ras algorithm. [doc] [play]
- <big>RsaDecrypt</big> : decrypt data with ras algorithm. [doc] [play]
- <big>GenerateRsaKeyPair</big> : creates rsa private and public key. [doc] [play]
- <big>RsaEncryptOAEP</big> : encrypts the given data with RSA-OAEP. [doc] [play]
- <big>RsaDecryptOAEP</big> : decrypts the data with RSA-OAEP [doc] [play]
import "github.com/duke-git/lancet/v2/datetime"
Function list:
- <big>AddDay</big> : add or sub day to the time. [doc] [play]
- <big>AddHour</big> : add or sub day to the time. [doc] [play]
- <big>AddMinute</big> : add or sub day to the time. [doc] [play]
- <big>AddYear</big> : add or sub year to the time. [doc] [play]
- <big>BeginOfMinute</big> : return the date time at the begin of minute of specific date. [doc] [play]
- <big>BeginOfHour</big> : return the date time at the begin of hour of specific date. [doc] [play]
- <big>BeginOfDay</big> : return the date time at the begin of day of specific date. [doc] [play]
- <big>BeginOfWeek</big> : return the date time at the begin of week of specific date. [doc] [play]
- <big>BeginOfMonth</big> : return the date time at the begin of month of specific date. [doc] [play]
- <big>BeginOfYear</big> : return the date time at the begin of year of specific date. [doc] [play]
- <big>EndOfMinute</big> : return the date time at the end of minute of specific date. [doc] [play]
- <big>EndOfHour</big> : return the date time at the end of hour of specific date. [doc] [play]
- <big>EndOfDay</big> : return the date time at the end of day of specific date. [doc] [play]
- <big>EndOfWeek</big> : return the date time at the end of week of specific date. [doc] [play]
- <big>EndOfMonth</big> : return the date time at the end of month of specific date. [doc] [play]
- <big>EndOfYear</big> : return the date time at the end of year of specific date. [doc] [play]
- <big>GetNowDate</big> : return format yyyy-mm-dd of current date. [doc] [play]
- <big>GetNowTime</big> : return format hh-mm-ss of current time. [doc] [play]
- <big>GetNowDateTime</big> : return format yyyy-mm-dd hh-mm-ss of current datetime. [doc] [play]
- <big>GetTodayStartTime</big> : return the start time of today, format: yyyy-mm-dd 00:00:00. [doc] [play]
- <big>GetTodayEndTime</big> : return the end time of today, format: yyyy-mm-dd 23:59:59. [doc] [play]
- <big>GetZeroHourTimestamp</big> : return timestamp of zero hour (timestamp of 00:00). [doc] [play]
- <big>GetNightTimestamp</big> : return timestamp of zero hour (timestamp of 23:59). [doc] [play]
- <big>FormatTimeToStr</big> : convert time to string. [doc] [play]
- <big>FormatStrToTime</big> : convert string to time. [doc] [play]
- <big>NewUnix</big> : return unix timestamp of specific time. [doc] [play]
- <big>NewUnixNow</big> : return unix timestamp of current time. [doc] [play]
- <big>NewFormat</big> : return unix timestamp of specific time string, t should be "yyyy-mm-dd hh:mm:ss". [doc] [play]
- <big>NewISO8601</big> : return unix timestamp of specific iso8601 time string. [doc] [play]
- <big>ToUnix</big> : return unix timestamp. [doc] [play]
- <big>ToFormat</big> : return the time string 'yyyy-mm-dd hh:mm:ss' of unix time. [doc] [play]
- <big>ToFormatForTpl</big> : return the time string which format is specific tpl. [doc] [play]
- <big>ToIso8601</big> : return iso8601 time string. [doc] [play]
- <big>IsLeapYear</big> : check if param
year
is leap year or not. [doc] [play] - <big>BetweenSeconds</big> : returns the number of seconds between two times. [doc] [play]
- <big>DayOfYear</big> : returns which day of the year the parameter date
t
is. [doc] [play] - <big>IsWeekend</big> : checks if passed time is weekend or not. [doc] [play]
- <big>NowDateOrTime</big> : returns current datetime with specific format and timezone. [doc] [play]
- <big>Timestamp</big> : returns current second timestamp. [doc]
- <big>TimestampMilli</big> : returns current mill second timestamp. [doc] [play]
- <big>TimestampMicro</big> : returns current micro second timestamp. [doc] [play]
- <big>TimestampNano</big> : returns current nano second timestamp. [doc] [play]
- <big>TrackFuncTime</big> : tracks function execution time. [doc] [play]
- <big>DaysBetween</big> : returns the number of days between two times. [doc] [play]
- <big>GenerateDatetimesBetween</big> : returns a slice of strings between two times. [doc] [play]
import list "github.com/duke-git/lancet/v2/datastructure/list"
import copyonwritelist "github.com/duke-git/lancet/v2/datastructure/copyonwritelist"
import link "github.com/duke-git/lancet/v2/datastructure/link"
import stack "github.com/duke-git/lancet/v2/datastructure/stack"
import queue "github.com/duke-git/lancet/v2/datastructure/queue"
import set "github.com/duke-git/lancet/v2/datastructure/set"
import tree "github.com/duke-git/lancet/v2/datastructure/tree"
import heap "github.com/duke-git/lancet/v2/datastructure/heap"
import hashmap "github.com/duke-git/lancet/v2/datastructure/hashmap"
import optional "github.com/duke-git/lancet/v2/datastructure/optional"
Structure list:
- <big>List</big> : a linear table, implemented with slice. [doc]
- <big>CopyOnWriteList</big> : a thread-safe list implementation that uses go slicing as its base. [doc]
- <big>Link</big> : link list structure, contains singly link and doubly link. [doc]
- <big>Stack</big> : stack structure(fifo), contains array stack and link stack. [doc]
- <big>Queue</big> : queue structure(filo), contains array queue, circular queue, link queue and priority queue. [doc]
- <big>Set</big> : a data container, like slice, but element of set is not duplicate. [doc]
- <big>Tree</big> : binary search tree structure. [doc]
- <big>Heap</big> : a binary max heap. [doc]
- <big>Hashmap</big> : hash map structure. [doc]
- <big>Optional</big> : Optional container. [doc]
import "github.com/duke-git/lancet/v2/fileutil"
Function list๏ผ
- <big>ClearFile</big> : write empty string to target file. [doc] [play]
- <big>CreateFile</big> : create file in path. [doc] [play]
- <big>CreateDir</big> : create directory in absolute path. [doc] [play]
- <big>CopyFile</big> : copy src file to dest file. [doc] [play]
- <big>CopyDir</big> : copy src directory to dest directory. [doc] [play]
- <big>FileMode</big> : return file's mode and permission. [doc] [play]
- <big>MiMeType</big> : return file mime type. [doc] [play]
- <big>IsExist</big> : checks if a file or directory exists. [doc] [play]
- <big>IsLink</big> : checks if a file is symbol link or not. [doc] [play]
- <big>IsDir</big> : checks if the path is directory or not. [doc] [play]
- <big>ListFileNames</big> : return all file names in the path. [doc] [play]
- <big>RemoveFile</big> : remove file, param should be file path. [doc] [play]
- <big>ReadFileToString</big> : return string of file content. [doc] [play]
- <big>ReadFileByLine</big> : read file line by line, return string slice of file content. [doc] [play]
- <big>Zip</big> : create a zip file of fpath, fpath could be a file or a directory. [doc] [play]
- <big>ZipAppendEntry</big> : append a single file or directory by fpath to an existing zip file. [doc]
- <big>UnZip</big> : unzip the zip file and save it to dest path. [doc] [play]
- <big>CurrentPath</big> : return current absolute path. [doc] [play]
- <big>IsZipFile</big> : checks if file is zip file or not. [doc] [play]
- <big>FileSize</big> : return file size in bytes. [doc] [play]
- <big>MTime</big> : return file modified time(unix timestamp). [doc] [play]
- <big>Sha</big> : return file sha value. [doc] [play]
- <big>ReadCsvFile</big> : read file content into slice. [doc] [play]
- <big>WriteCsvFile</big> : write content to target csv file. [doc]
- <big>WriteMapsToCsv</big> : write slice of map to csv file. [doc] [play]
- <big>WriteBytesToFile</big> : write bytes to target file. [doc] [play]
- <big>WriteStringToFile</big> : write string to target file. [doc] [play]
- <big>ReadFile</big> : read file or url. [doc]
- <big>ChunkRead</big> : reads a block from the file at the specified offset and returns all lines within the block. [doc] [play]
- <big>ParallelChunkRead</big> : reads the file in parallel and send each chunk of lines to the specified channel.
[doc]
[play]
import "github.com/duke-git/lancet/v2/formatter"
Function list:
- <big>Comma</big> : add comma to a number value by every 3 numbers from right, ahead by a prefix symbol char. [doc] [play]
- <big>Pretty</big> : pretty print data to JSON string. [doc] [play]
- <big>PrettyToWriter</big> : pretty encode data to writer. [doc] [play]
- <big>DecimalBytes</big> : returns a human readable byte size under decimal standard (base 1000). [doc] [play]
- <big>BinaryBytes</big> : returns a human-readable byte size under binary standard (base 1024). [doc] [play]
- <big>ParseDecimalBytes</big> : return the human readable bytes size string into the amount it represents(base 1000). [doc] [play]
- <big>ParseBinaryBytes</big> : return the human readable bytes size string into the amount it represents(base 1024). [doc] [play]
import "github.com/duke-git/lancet/v2/function"
Function list:
- <big>After</big> : return a function that invokes passed function once the returned function is called more than n times. [doc] [play]
- <big>Before</big> : return a function that invokes passed function once the returned function is called less than n times [doc] [play]
- <big>CurryFn</big> : make a curry function. [doc] [play]
- <big>Compose</big> : compose the functions from right to left. [doc] [play]
- <big>Delay</big> : call the function after delayed time. [doc] [play]
- <big>Debounced<sup>deprecated</sup></big> : creates a debounced function that delays invoking fn until after wait duration have elapsed since the last time the debounced function was invoked. [doc] [play]
- <big>Debounce</big> : creates a debounced version of the provided function. [doc] [play]
- <big>Throttle</big> : creates a throttled version of the provided function. [doc] [play]
- <big>Schedule</big> : invoke function every duration time, util close the returned bool channel. [doc] [play]
- <big>Pipeline</big> : takes a list of functions and returns a function whose param will be passed into the functions one by one. [doc] [play]
- <big>AcceptIf</big> : returns another function of the same signature as the apply function but also includes a bool value to indicate success or failure. [doc] [play]
- <big>And</big> : returns a composed predicate that represents the logical AND of a list of predicates. [doc] [play]
- <big>Or</big> : returns a composed predicate that represents the logical OR of a list of predicates. [doc] [play]
- <big>Negate</big> : returns a predicate that represents the logical negation of this predicate. [doc] [play]
- <big>Nor</big> : returns a composed predicate that represents the logical NOR of a list of predicates. [doc] [play]
- <big>Nand</big> : returns a composed predicate that represents the logical Nand of a list of predicates. [doc] [play]
- <big>Xnor</big> : returns a composed predicate that represents the logical XNOR of a list of predicates. [doc] [play]
- <big>Watcher</big> : Watcher is used for record code execution time. can start/stop/reset the watch timer. get the elapsed time of function execution. [doc] [play]
import "github.com/duke-git/lancet/v2/maputil"
Function list:
- <big>MapTo</big> : quick map any value to struct or any base type. [doc] [play]
- <big>ForEach</big> : executes iteratee function for every key and value pair in map. [doc] [play]
- <big>Filter</big> : iterates over map, return a new map contains all key and value pairs pass the predicate function. [doc] [play]
- <big>FilterByKeys</big> : iterates over map, return a new map whose keys are all given keys [doc] [play]
- <big>FilterByValues</big> : iterates over map, return a new map whose values are all given values. [doc] [play]
- <big>OmitBy</big> : the opposite of Filter, removes all the map elements for which the predicate function returns true. [doc] [play]
- <big>OmitByKeys</big> : the opposite of FilterByKeys, extracts all the map elements which keys are not omitted. [doc] [play]
- <big>OmitByValues</big> : the opposite of FilterByValues. remove all elements whose value are in the give slice. [doc] [play]
- <big>Intersect</big> : iterates over maps, return a new map of key and value pairs in all given maps. [doc] [play]
- <big>Keys</big> : returns a slice of the map's keys. [doc] [play]
- <big>KeysBy</big> : creates a slice whose element is the result of function mapper invoked by every map's key. [doc] [play]
- <big>Merge</big> : merge maps, next key will overwrite previous key. [doc] [play]
- <big>Minus</big> : creates a map of whose key in mapA but not in mapB. [doc] [play]
- <big>Values</big> : returns a slice of the map's values. [doc] [play]
- <big>ValuesBy</big> : creates a slice whose element is the result of function mapper invoked by every map's value. [doc] [play]
- <big>MapKeys</big> : transforms a map to other type map by manipulating it's keys. [doc] [play]
- <big>MapValues</big> : transforms a map to other type map by manipulating it's values. [doc] [play]
- <big>Entries</big> : transforms a map into array of key/value pairs. [doc] [play]
- <big>FromEntries</big> : creates a map based on a slice of key/value pairs. [doc] [play]
- <big>Transform</big> : transform a map to another type map. [doc] [play]
- <big>IsDisjoint</big> : check two map are disjoint if they have no keys in common. [doc] [play]
- <big>HasKey</big> : checks if map has key or not. [doc] [play]
- <big>GetOrSet</big> : returns value of the given key or set the given value value if not present. [doc] [play]
- <big>MapToStruct</big> : converts map to struct. [doc] [play]
- <big>ToSortedSlicesDefault</big> : converts a map to two slices sorted by key: one for the keys and another for the values. [doc] [play]
- <big>ToSortedSlicesWithComparator</big> : converts a map to two slices sorted by key and using a custom comparison function: one for the keys and another for the values. [doc] [play]
- <big>NewOrderedMap</big> : creates a new OrderedMap. [doc] [play]
- <big>OrderedMap_Set</big> : sets the given key-value pair for ordered map. [doc] [play]
- <big>OrderedMap_Get</big> : returns the value for the given key. [doc] [play]
- <big>OrderedMap_Delete</big> : deletes the key-value pair for the given key. [doc] [play]
- <big>OrderedMap_Clear</big> : clears the ordered map. [doc] [play]
- <big>OrderedMap_Front</big> : returns the first key-value pair. [doc] [play]
- <big>OrderedMap_Back</big> : returns the last key-value pair. [doc] [play]
- <big>OrderedMap_Range</big> : calls the given function for each key-value pair. [doc] [play]
- <big>OrderedMap_Keys</big> : returns the keys in order. [doc] [play]
- <big>OrderedMap_Values</big> : returns the values in order. [doc] [play]
- <big>OrderedMap_Elements</big> : returns the key-value pairs in order. [doc] [play]
- <big>OrderedMap_Len</big> : returns the number of key-value pairs. [doc] [play]
- <big>OrderedMap_Contains</big> : returns true if the given key exists. [doc] [play]
- <big>OrderedMap_Iter</big> : returns a channel that yields key-value pairs in order. [doc] [play]
- <big>OrderedMap_ReverseIter</big> : returns a channel that yields key-value pairs in reverse order. [doc] [play]
- <big>OrderedMap_SortByKey</big> : sorts the map by key given less function. [doc] [play]
- <big>OrderedMap_MarshalJSON</big> : implements the json.Marshaler interface. [doc] [play]
- <big>OrderedMap_UnmarshalJSON</big> : implements the json.Unmarshaler interface. [doc] [play]
- <big>NewConcurrentMap</big> : creates a ConcurrentMap with specific shard count. [doc] [play]
- <big>ConcurrentMap_Set</big> : set the value for a key. [doc] [play]
- <big>ConcurrentMap_Get</big> : get the value stored in the map for a key, or nil if no. [doc] [play]
- <big>ConcurrentMap_GetOrSet</big> : returns the existing value for the key if present. [doc] [play]
- <big>ConcurrentMap_Delete</big> : delete the value for a key. [doc] [play]
- <big>ConcurrentMap_GetAndDelete</big> :returns the existing value for the key if present and then delete the value for the key. [doc] [play]
- <big>ConcurrentMap_Has</big> : checks if map has the value for a key. [doc] [play]
- <big>ConcurrentMap_Range</big> : calls iterator sequentially for each key and value present in each of the shards in the map. [doc] [play]
- <big>SortByKey</big> : sorts the map by its keys and returns a new map with sorted keys. [doc] [play]
- <big>GetOrDefault</big> : returns the value of the given key or a default value if the key is not present. [doc] [play]
import "github.com/duke-git/lancet/v2/mathutil"
Function list:
- <big>Average</big> :return average value of numbers. [doc] [play]
- <big>Exponent</big> : calculate x^n for int64. [doc] [play]
- <big>Fibonacci</big> :calculate fibonacci number before n for int. [doc] [play]
- <big>Factorial</big> : calculate x! for uint. [doc] [play]
- <big>Max</big> : return maximum value of numbers. [doc] [play]
- <big>MaxBy</big> : return the maximum value of a slice using the given comparator function. [doc] [play]
- <big>Min</big> : return minimum value of numbers. [doc] [play]
- <big>MinBy</big> : return the minimum value of a slice using the given comparator function. [doc] [play]
- <big>Percent</big> : calculate the percentage of value to total. [doc] [play]
- <big>RoundToFloat</big> : round up to n decimal places for float64. [doc] [play]
- <big>RoundToString</big> : round up to n decimal places for float64, return string. [doc] [play]
- <big>TruncRound</big> : round off n decimal places for int64. [doc] [play]
- <big>CeilToFloat</big> : round float up n decimal places. [doc] [play]
- <big>CeilToString</big> : round float up n decimal places, then conver to string. [doc] [play]
- <big>FloorToFloat</big> : round float down n decimal places. [doc] [play]
- <big>FloorToString</big> : round float down n decimal places, then conver to string. [doc] [play]
- <big>Range</big> : Creates a slice of numbers from start with specified count, element step is 1. [doc] [play]
- <big>RangeWithStep</big> : Creates a slice of numbers from start to end with specified step. [doc] [play]
- <big>AngleToRadian</big> : converts angle value to radian value. [doc] [play]
- <big>RadianToAngle</big> : converts radian value to angle value. [doc] [play]
- <big>PointDistance</big> : get two points distance. [doc] [play]
- <big>IsPrime</big> : checks if number is prime number. [doc] [play]
- <big>GCD</big> : return greatest common divisor (GCD) of integers. [doc] [play]
- <big>LCM</big> : return Least Common Multiple (LCM) of integers. [doc] [play]
- <big>Cos</big> : return the cosine of the radian argument. [doc] [play]
- <big>Sin</big> : return the sine of the radian argument. [doc] [play]
- <big>Log</big> : returns the logarithm of base n. [doc] [play]
- <big>Sum</big> : return sum of passed numbers. [doc] [play]
- <big>Abs</big> : returns the absolute value of param number. [doc] [play]
- <big>Div</big> : returns the result of x divided by y. [doc] [play]
import "github.com/duke-git/lancet/v2/netutil"
Function list:
- <big>ConvertMapToQueryString</big> : convert map to sorted url query string. [doc] [play]
- <big>EncodeUrl</big> : encode url(?a=1&b=[2] -> ?a=1&b=%5B2%5D). [doc] [play]
- <big>GetInternalIp</big> : return internal ipv4. [doc] [play]
- <big>GetIps</big> : return all ipv4 of current system. [doc] [play]
- <big>GetMacAddrs</big> : return mac address of current system. [doc] [play]
- <big>GetPublicIpInfo</big> : return public ip information. [doc] [play]
- <big>GetRequestPublicIp</big> : return the http request public ip. [doc] [play]
- <big>IsPublicIP</big> : verify a ip is public or not. [doc] [play]
- <big>IsInternalIP</big> : verify an ip is intranet or not. [doc] [play]
- <big>HttpRequest</big> : a composed http request used for HttpClient send request. [doc] [play]
- <big>HttpClient</big> : a http client tool, used for sending http request [doc] [play]
- <big>SendRequest</big> : send http request. [doc] [play]
- <big>DecodeResponse</big> : decode http response into target object. [doc] [play]
- <big>StructToUrlValues</big> : convert struct to url values. [doc] [play]
- <big>HttpGet<sup>deprecated</sup></big> : send http get request. [doc]
- <big>HttpDelete<sup>deprecated</sup></big> : send http delete request. [doc]
- <big>HttpPost<sup>deprecated</sup></big> : send http post request. [doc]
- <big>HttpPut<sup>deprecated</sup></big> : send http put request. [doc]
- <big>HttpPatch<sup>deprecated</sup></big> : send http patch request. [doc]
- <big>ParseHttpResponse</big> : decode http response into target object. [doc]
- <big>DownloadFile</big> : download the file exist in url to a local file. [doc]
- <big>UploadFile</big> : upload the file to a server. [doc]
- <big>IsPingConnected</big> : checks if can ping the specified host or not. [doc] [play]
- <big>IsTelnetConnected</big> : checks if can if can telnet the specified host or not. [doc] [play]
import "github.com/duke-git/lancet/v2/pointer"
Function list:
- <big>ExtractPointer</big> : return the underlying value by the given interface type. [doc] [play]
- <big>Of</big> : return a pointer to the value
v
. [doc] [play] - <big>Unwrap</big> : return the value from the pointer. [doc] [play]
- <big>UnwrapOr</big> : UnwrapOr returns the value from the pointer or fallback if the pointer is nil. [doc] [play]
- <big>UnwarpOrDefault</big> : UnwarpOrDefault returns the value from the pointer or the default value if the pointer is nil. [doc] [play]
import "github.com/duke-git/lancet/v2/random"
Function list:
- <big>RandBytes</big> : generate random byte slice. [doc] [play]
- <big>RandInt</big> : generate random int number between min and max. [doc] [play]
- <big>RandString</big> : generate random string of specific length. [doc] [play]
- <big>RandUpper</big> : generate a random upper case string. [doc] [play]
- <big>RandLower</big> : generate a random lower case string. [doc] [play]
- <big>RandNumeral</big> : generate a random numeral string of specific length. [doc] [play]
- <big>RandNumeralOrLetter</big> : generate a random numeral or letter string. [doc] [play]
- <big>UUIdV4</big> : generate a random UUID of version 4 according to RFC 4122. [doc] [play]
- <big>RandUniqueIntSlice</big> : generate a slice of random int that do not repeat. [doc] [play]
- <big>RandSymbolChar</big> : generate a random symbol char of specified length. [doc] [play]
- <big>RandFloat</big> : generate a random float64 number between [min, max) with specific precision. [doc] [play]
- <big>RandFloats</big> : generate a slice of random float64 numbers that do not repeat. [doc] [play]
- <big>RandStringSlice</big> : generate a slice of random string of length strLen based on charset. [doc] [play]
- <big>RandBool</big> : generate a random boolean value (true or false). [doc] [play]
- <big>RandBoolSlice</big> : generate a random boolean slice of specified length. [doc] [play]
- <big>RandIntSlice</big> : generate a slice of random int. Number range in [min, max) [doc] [play]
- <big>RandFromGivenSlice</big> : generate a random element from given slice. [doc] [play]
- <big>RandSliceFromGivenSlice</big> : generate a random slice of length num from given slice. [doc] [play]
import "github.com/duke-git/lancet/v2/retry"
Function list:
- <big>Context</big> : set retry context config option. [doc] [play]
- <big>Retry</big> : executes the retryFunc repeatedly until it was successful or canceled by the context. [doc] [play]
- <big>RetryFunc</big> : function that retry executes. [doc] [play]
- <big>RetryDuration</big> : set duration of retry [doc] [play]
- <big>RetryTimes</big> : set times of retry. [doc] [play]
- <big>BackoffStrategy</big> : An interface that defines a method for calculating backoff intervals. [doc]
- <big>RetryWithCustomBackoff</big> : set abitary custom backoff strategy. [doc] [play]
- <big>RetryWithLinearBackoff</big> : set linear strategy backoff. [doc] [play]
- <big>RetryWithExponentialWithJitterBackoff</big> : set exponential strategy backoff. [doc] [play]
import "github.com/duke-git/lancet/v2/slice"
Function list:
- <big>AppendIfAbsent</big> : if the item is absent,append it to the slice. [doc] [play]
- <big>Contain</big> : check if the value is in the slice or not. [doc] [play]
- <big>ContainBy</big> : returns true if predicate function return true. [doc] [play]
- <big>ContainSubSlice</big> : check if the slice contain a given subslice or not. [doc] [play]
- <big>Chunk</big> : creates a slice of elements split into groups the length of size. [doc] [play]
- <big>Compact</big> : creates an slice with all falsy values removed. The values false, nil, 0, and "" are falsy. [doc] [play]
- <big>Concat</big> : creates a new slice concatenating slice with any additional slices. [doc] [play]
- <big>Count</big> : returns the number of occurrences of the given item in the slice. [doc] [play]
- <big>CountBy</big> : iterates over elements of slice with predicate function, returns the number of all matched elements. [doc] [play]
- <big>Difference</big> : creates an slice of whose element in slice but not in compared slice. [doc] [play]
- <big>DifferenceBy</big> : accepts iteratee which is invoked for each element of slice and values to generate the criterion by which they're compared. [doc] [play]
- <big>DifferenceWith</big> : accepts comparator which is invoked to compare elements of slice to values. [doc] [play]
- <big>DeleteAt</big> : delete the element of slice at index. [doc] [play]
- <big>DeleteRange</big> : delete the element of slice from start index to end index๏ผexclude). [doc] [play]
- <big>Drop</big> : drop n elements from the start of a slice. [doc] [play]
- <big>DropRight</big> : drop n elements from the end of a slice. [doc] [play]
- <big>DropWhile</big> : drop n elements from the start of a slice while predicate function returns true. [doc] [play]
- <big>DropRightWhile</big> : drop n elements from the end of a slice while predicate function returns true. [doc] [play]
- <big>Equal</big> : checks if two slices are equal: the same length and all elements' order and value are equal. [doc] [play]
- <big>EqualWith</big> : checks if two slices are equal with comparator func. [doc] [play]
- <big>Every</big> : return true if all of the values in the slice pass the predicate function. [doc] [play]
- <big>Filter</big> : iterates over elements of slice, returning an slice of all elements pass the predicate function. [doc] [play]
- <big>FilterMap</big> : returns a slice which apply both filtering and mapping to the given slice. [doc] [play]
- <big>Find<sup>deprecated</sup></big> : iterates over elements of slice, returning the first one that passes a truth test on predicate function. [doc] [play]
- <big>FindBy</big> : iterates over elements of slice, returning the first one that passes a truth test on predicate function. [doc] [play]
- <big>FindLast<sup>deprecated</sup></big> : return the last item that passes a truth test on predicate function. [doc] [play]
- <big>FindLastBy</big> : iterates over elements of slice, returning the last one that passes a truth test on predicate function. [doc] [play]
- <big>Flatten</big> : flattens slice one level. [doc] [play]
- <big>FlattenDeep</big> : flattens slice recursive to one level. [doc] [play]
- <big>FlatMap</big> : manipulates a slice and transforms and flattens it to a slice of another type. [doc] [play]
- <big>ForEach</big> : iterates over elements of slice and invokes function for each element. [doc] [play]
- <big>ForEachWithBreak</big> : iterates over elements of slice and invokes function for each element, when iteratee return false, will break the for each loop. [doc] [play]
- <big>ForEachConcurrent</big> : applies the iteratee function to each item in the slice concurrently. [doc] [play]
- <big>GroupBy</big> : iterate over elements of the slice, each element will be group by criteria, returns two slices. [doc] [play]
- <big>GroupWith</big> : return a map composed of keys generated from the results of running each element of slice thru iteratee. [doc] [play]
- <big>IntSlice<sup>deprecated</sup></big> : convert param to int slice. [doc] [play]
- <big>InterfaceSlice<sup>deprecated</sup></big> : convert param to interface slice. [doc] [play]
- <big>Intersection</big> : creates a slice of unique elements that included by all slices. [doc] [play]
- <big>InsertAt</big> : insert the value or other slice into slice at index. [doc] [play]
- <big>IndexOf</big> : returns the index at which the first occurrence of an item is found in a slice. [doc] [play]
- <big>LastIndexOf</big> : returns the index at which the last occurrence of the item is found in a slice. [doc] [play]
- <big>Map</big> : creates an slice of values by running each element of slice thru iteratee function. [doc] [play]
- <big>MapConcurrent</big> : applies the iteratee function to each item in the slice by concrrent. [doc] [play]
- <big>Merge</big> : merge all given slices into one slice. [doc] [play]
- <big>Reverse</big> : return slice of element order is reversed to the given slice. [doc] [play]
- <big>Reduce<sup>deprecated</sup></big> : creates an slice of values by running each element of slice thru iteratee function.(Deprecated: use ReduceBy) [doc] [play]
- <big>ReduceBy</big> : produces a value from slice by accumulating the result of each element as passed through the reducer function. [doc] [play]
- <big>ReduceRight</big> : ReduceRight is like ReduceBy, but it iterates over elements of slice from right to left. [doc] [play]
- <big>ReduceConcurrent</big> : reduces the slice to a single value by applying the reducer function to each item in the slice concurrently. [doc] [play]
- <big>Replace</big> : returns a copy of the slice with the first n non-overlapping instances of old replaced by new. [doc] [play]
- <big>ReplaceAll</big> : returns a copy of the slice with all non-overlapping instances of old replaced by new. [doc] [play]
- <big>Repeat</big> : creates a slice with length n whose elements are passed item. [doc] [play]
- <big>Shuffle</big> : shuffle the slice. [doc] [play]
- <big>IsAscending</big> : Checks if a slice is ascending order. [doc] [play]
- <big>IsDescending</big> : Checks if a slice is descending order. [doc] [play]
- <big>IsSorted</big> : Checks if a slice is sorted (ascending or descending). [doc] [play]
- <big>IsSortedByKey</big> : Checks if a slice is sorted by iteratee function. [doc] [play]
- <big>Sort</big> : sorts a slice of any ordered type(number or string). [doc] [play]
- <big>SortBy</big> : sorts the slice in ascending order as determined by the less function. [doc] [play]
- <big>SortByField<sup>deprecated</sup></big> : return sorted slice by specific field. [doc] [play]
- <big>Some</big> : return true if any of the values in the list pass the predicate function. [doc] [play]
- <big>StringSlice<sup>deprecated</sup></big> : convert param to slice of string. [doc] [play]
- <big>SymmetricDifference</big> : the symmetric difference of two slice, also known as the disjunctive union. [doc] [play]
- <big>ToSlice</big> : returns a slices of a variable parameter transformation. [doc] [play]
- <big>ToSlicePointer</big> : returns a pointer to the slices of a variable parameter transformation. [doc] [play]
- <big>Unique</big> : remove duplicate elements in slice. [doc] [play]
- <big>UniqueBy</big> : remove duplicate elements from the input slice based on the values returned by the iteratee function. [doc] [play]
- <big>UniqueByComparator</big> : remove duplicate elements from the input slice using the provided comparator function. [doc] [play]
- <big>UniqueByField</big> : remove duplicate elements in struct slice by struct field. [doc] [play]
- <big>UniqueByConcurrent</big> : remove duplicate elements from the slice by concurrent. [doc] [play]
- <big>Union</big> : creates a slice of unique elements, in order, from all given slices. [doc] [play]
- <big>UnionBy</big> : accepts iteratee which is invoked for each element of each slice, then union slice. [doc] [play]
- <big>UpdateAt</big> : update the slice element at index. [doc] [play]
- <big>Without</big> : creates a slice excluding all given items. [doc] [play]
- <big>KeyBy</big> : converts a slice to a map based on a callback function. [doc] [play]
- <big>Join</big> : join the slice item with specify separator. [doc] [play]
- <big>Partition</big> : partition all slice elements with the evaluation of the given predicate functions. [doc] [play]
- <big>Random</big> : get a random item of slice, return its index, when slice is empty, return -1. [doc] [play]
- <big>SetToDefaultIf</big> : set elements to their default value if they match the given predicate. [doc] [play]
- <big>Break</big> : breaks a list into two parts at the point where the predicate for the first time is true. [doc]
- <big>RightPadding</big> : adds padding to the right end of a slice. [doc] [play]
- <big>LeftPadding</big> : adds padding to the left begin of a slice. [doc] [play]
- <big>Frequency</big> : counts the frequency of each element in the slice. [doc] [play]
import "github.com/duke-git/lancet/v2/stream"
Function list:
- <big>Of</big> : creates a stream whose elements are the specified values. [doc] [play]
- <big>FromSlice</big> : creates a stream from slice. [doc] [play]
- <big>FromChannel</big> : creates a stream from channel. [doc] [play]
- <big>FromRange</big> : creates a number stream from start to end. both start and end are included. [start, end] [doc] [play]
- <big>Generate</big> : creates a stream where each element is generated by the provided generator function. [doc] [play]
- <big>Concat</big> : creates a lazily concatenated stream whose elements are all the elements of the first stream followed by all the elements of the second stream. [doc] [play]
- <big>Distinct</big> : creates returns a stream that removes the duplicated items. [doc] [play]
- <big>Filter</big> : returns a stream consisting of the elements of this stream that match the given predicate. [doc] [play]
- <big>FilterConcurrent</big> : Applies the provided filter function
predicate
to each element of the input slice concurrently. [doc] [play] - <big>Map</big> : returns a stream consisting of the elements of this stream that apply the given function to elements of stream. [doc] [play]
- <big>Peek</big> : returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream. [doc] [play]
- <big>Skip</big> : returns a stream consisting of the remaining elements of this stream after discarding the first n elements of the stream. [doc] [play]
- <big>Limit</big> : returns a stream consisting of the elements of this stream, truncated to be no longer than maxSize in length. [doc] [play]
- <big>Reverse</big> : returns a stream whose elements are reverse order of given stream. [doc] [play]
- <big>Range</big> : returns a stream whose elements are in the range from start(included) to end(excluded) original stream. [doc] [play]
- <big>Sorted</big> : returns a stream consisting of the elements of this stream, sorted according to the provided less function. [doc] [play]
- <big>ForEach</big> : performs an action for each element of this stream. [doc] [play]
- <big>Reduce</big> : performs a reduction on the elements of this stream, using an associative accumulation function, and returns an Optional describing the reduced value, if any. [doc] [play]
- <big>FindFirst</big> : returns the first element of this stream and true, or zero value and false if the stream is empty. [doc] [play]
- <big>FindLast</big> : returns the last element of this stream and true, or zero value and false if the stream is empty. [doc] [play]
- <big>Max</big> : returns the maximum element of this stream according to the provided less function. less function: a > b [doc] [play]
- <big>Min</big> : returns the minimum element of this stream according to the provided less function. less function: a < b [doc] [play]
- <big>AllMatch</big> : returns whether all elements of this stream match the provided predicate. [doc] [play]
- <big>AnyMatch</big> : returns whether any elements of this stream match the provided predicate. [doc] [play]
- <big>NoneMatch</big> : returns whether no elements of this stream match the provided predicate. [doc] [play]
- <big>Count</big> : returns the count of elements in the stream. [doc] [play]
- <big>ToSlice</big> : returns the elements in the stream. [doc] [play]
import "github.com/duke-git/lancet/v2/structs"
Function list:
- <big>New</big> : creates a
Struct
instance. [doc] - <big>ToMap</big> : converts a valid struct to a map. [doc]
- <big>Fields</big> : get all fields of a given struct, that the fields are abstract struct field. [doc]
- <big>IsStruct</big> : check if the struct is valid. [doc]
- <big>Tag</big> : get a
Tag
of theField
,Tag
is a abstract struct field tag. [doc] - <big>Name</big> : get the field name. [doc]
- <big>Value</big> : get the
Field
underlying value. [doc] - <big>Kind</big> : get the field's kind. [doc]
- <big>IsEmbedded</big> : check if the field is an embedded field. [doc]
- <big>IsExported</big> : check if the field is exported. [doc]
- <big>IsZero</big> : check if the field is zero value. [doc]
- <big>IsSlice</big> : check if the field is a slice. [doc]
- <big>IsTargetType</big> : check if the field is target type. [doc]
import "github.com/duke-git/lancet/v2/strutil"
Function list:
- <big>After</big> : returns the substring after the first occurrence of a specific string in the source string. [doc] [play]
- <big>AfterLast</big> : returns the substring after the last occurrence of a specific string in the source string. [doc] [play]
- <big>Before</big> : returns the substring before the first occurrence of a specific string in the source string. [doc] [play]
- <big>BeforeLast</big> : returns the substring before the last occurrence of a specific string in the source string. [doc] [play]
- <big>CamelCase</big> : coverts source string to its camelCase string. [doc] [play]
- <big>Capitalize</big> : converts the first character of source string to upper case and the remaining to lower case. [doc] [play]
- <big>ContainsAll</big> : return true if target string contains all the substrings. [doc] [play]
- <big>ContainsAny</big> : return true if target string contains any one of the substrings. [doc] [play]
- <big>IsString</big> : checks if the parameter value data type is string or not. [doc] [play]
- <big>KebabCase</big> : coverts string to kebab-case string. [doc] [play]
- <big>UpperKebabCase</big> : coverts string to upper KEBAB-CASE string. [doc] [play]
- <big>LowerFirst</big> : converts the first character of string to lower case. [doc] [play]
- <big>UpperFirst</big> : converts the first character of string to upper case. [doc] [play]
- <big>Pad</big> : pads string on the left and right side if it's shorter than size. [doc] [play]
- <big>PadEnd</big> : pads string with given characters on the right side if it's shorter than limit size. Padding characters are truncated if they exceed size. [doc] [play]
- <big>PadStart</big> : pads string with given characters on the left side if it's shorter than limit size. Padding characters are truncated if they exceed size. [doc] [play]
- <big>Reverse</big> : returns string whose char order is reversed to the given string. [doc] [play]
- <big>SnakeCase</big> : coverts string to snake_case string. [doc] [play]
- <big>UpperSnakeCase</big> : coverts string to upper SNAKE_CASE string. [doc] [play]
- <big>SplitEx</big> : split a given string which can control the result slice contains empty string or not. [doc] [play]
- <big>Substring</big> : returns a substring of the specific length starting at the specific offset position. [doc] [play]
- <big>Wrap</big> : wrap a string with given string. [doc] [play]
- <big>Unwrap</big> : unwrap a given string from anther string. will change source string. [doc] [play]
- <big>SplitWords</big> : splits a string into words, word only contains alphabetic characters. [doc] [play]
- <big>WordCount</big> : return the number of meaningful word of a string, word only contains alphabetic characters. [doc] [play]
- <big>RemoveNonPrintable</big> : remove non-printable characters from a string. [doc] [play]
- <big>StringToBytes</big> : converts a string to byte slice without a memory allocation. [doc] [play]
- <big>BytesToString</big> : converts a byte slice to string without a memory allocation. [doc] [play]
- <big>IsBlank</big> : checks if a string is whitespace or empty. [doc] [play]
- <big>IsNotBlank</big> : checks if a string is not whitespace or not empty. [doc] [play]
- <big>HasPrefixAny</big> : checks if a string starts with any of an array of specified strings. [doc] [play]
- <big>HasSuffixAny</big> : checks if a string ends with any of an array of specified strings. [doc] [play]
- <big>IndexOffset</big> : returns the index of the first instance of substr in string after offsetting the string by
idxFrom
. [doc] [play] - <big>ReplaceWithMap</big> : returns a copy of
str
, which is replaced by a map in unordered way, case-sensitively. [doc] [play] - <big>Trim</big> : strips whitespace (or other characters) from the beginning and end of a string. [doc] [play]
- <big>SplitAndTrim</big> : splits string
str
by a stringdelimiter
to a slice, and calls Trim to every element of slice. [doc] [play] - <big>HideString</big> : Hide some chars in source string with param
replaceChar
. [doc] [play] - <big>RemoveWhiteSpace</big> : remove whitespace characters from a string. [doc] [play]
- <big>SubInBetween</big> : return substring between the start and end position(excluded) of source string. [doc] [play]
- <big>HammingDistance</big> : calculates the Hamming distance between two strings. [doc] [play]
- <big>Concat</big> : concatenates strings. [doc] [play]
- <big>Ellipsis</big> : truncates a string to a specified length and appends an ellipsis. [doc] [play]
- <big>Shuffle</big> : shuffle the order of characters of given string. [doc] [play]
- <big>Rotate</big> : rotates the string by the specified number of characters. [doc] [play]
- <big>TemplateReplace</big> : replaces the placeholders in the template string with the corresponding values in the data map. [doc] [play]
- <big>RegexMatchAllGroups</big> : matches all subgroups in a string using a regular expression and returns the result. [doc] [play]
import "github.com/duke-git/lancet/v2/system"
Function list:
- <big>IsWindows</big> : check if current os is windows. [doc] [play]
- <big>IsLinux</big> : check if current os is linux. [doc] [play]
- <big>IsMac</big> : check if current os is macos. [doc] [play]
- <big>GetOsEnv</big> : get the value of the environment variable named by the key. [doc] [play]
- <big>SetOsEnv</big> : set the value of the environment variable named by the key. [doc] [play]
- <big>RemoveOsEnv</big> : remove a single environment variable. [doc] [play]
- <big>CompareOsEnv</big> : get env named by the key and compare it with passed env. [doc] [play]
- <big>ExecCommand</big> : execute command, return the stdout and stderr string of command, and error if error occurs. [doc] [play]
- <big>GetOsBits</big> : return current os bits (32 or 64). [doc] [play]
- <big>StartProcess</big> : start a new process with the specified name and arguments. [doc] [play]
- <big>StopProcess</big> : stop a process by pid. [doc] [play]
- <big>KillProcess</big> : kill a new process with the specified name and arguments. [doc] [play]
- <big>GetProcessInfo</big> : retrieves detailed process information by pid. [doc] [play]
import "github.com/duke-git/lancet/v2/tuple"
Function list:
- <big>Tuple2</big> : represents a 2 elements tuple. [doc] [play]
- <big>Tuple2_Unbox</big> : returns values in Tuple2. [doc] [play]
- <big>Zip2</big> : create a slice of Tuple2, whose elements are correspond to the given slice elements. [doc] [play]
- <big>Unzip2</big> : create a group of slice from a slice of Tuple2. [doc] [play]
- <big>Tuple3</big> : represents a 3 elements tuple. [doc] [play]
- <big>Tuple3_Unbox</big> : returns values in Tuple3. [doc] [play]
- <big>Zip3</big> : create a slice of Tuple3, whose elements are correspond to the given slice elements. [doc] [play]
- <big>Unzip3</big> : create a group of slice from a slice of Tuple3. [doc] [play]
- <big>Tuple4</big> : represents a 4 elements tuple. [doc] [play]
- <big>Tuple4_Unbox</big> : returns values in Tuple4. [doc] [play]
- <big>Zip4</big> : create a slice of Tuple4, whose elements are correspond to the given slice elements. [doc] [play]
- <big>Unzip4</big> : create a group of slice from a slice of Tuple4. [doc] [play]
- <big>Tuple5</big> : represents a 5 elements tuple. [doc] [play]
- <big>Tuple5_Unbox</big> : returns values in Tuple4. [doc] [play]
- <big>Zip5</big> : create a slice of Tuple5, whose elements are correspond to the given slice elements. [doc] [play]
- <big>Unzip5</big> : create a group of slice from a slice of Tuple5. [doc] [play]
- <big>Tuple6</big> : represents a 6 elements tuple. [doc] [play]
- <big>Tuple6_Unbox</big> : returns values in Tuple6. [doc] [play]
- <big>Zip6</big> : create a slice of Tuple6, whose elements are correspond to the given slice elements. [doc] [play]
- <big>Unzip6</big> : create a group of slice from a slice of Tuple6. [doc] [play]
- <big>Tuple7</big> : represents a 7 elements tuple. [doc] [play]
- <big>Tuple7_Unbox</big> : returns values in Tuple7. [doc] [play]
- <big>Zip7</big> : create a slice of Tuple7, whose elements are correspond to the given slice elements. [doc] [play]
- <big>Unzip7</big> : create a group of slice from a slice of Tuple7. [doc] [play]
- <big>Tuple8</big> : represents a 8 elements tuple. [doc] [play]
- <big>Tuple8_Unbox</big> : returns values in Tuple8. [doc] [play]
- <big>Zip8</big> : create a slice of Tuple8, whose elements are correspond to the given slice elements. [doc] [play]
- <big>Unzip8</big> : create a group of slice from a slice of Tuple8. [doc] [play]
- <big>Tuple9</big> : represents a 9 elements tuple. [doc] [play]
- <big>Tuple9_Unbox</big> : returns values in Tuple9. [doc] [play]
- <big>Zip9</big> : create a slice of Tuple9, whose elements are correspond to the given slice elements. [doc] [play]
- <big>Unzip9</big> : create a group of slice from a slice of Tuple9. [doc] [play]
- <big>Tuple10</big> : represents a 10 elements tuple. [doc] [play]
- <big>Tuple10_Unbox</big> : returns values in Tuple10. [doc] [play]
- <big>Zip10</big> : create a slice of Tuple10, whose elements are correspond to the given slice elements. [doc] [play]
- <big>Unzip10</big> : create a group of slice from a slice of Tuple10. [doc] [play]
import "github.com/duke-git/lancet/v2/validator"
Function list:
- <big>ContainChinese</big> : check if the string contain mandarin chinese. [doc] [play]
- <big>ContainLetter</big> : check if the string contain at least one letter. [doc] [play]
- <big>ContainLower</big> : check if the string contain at least one lower case letter a-z. [doc] [play]
- <big>ContainUpper</big> : check if the string contain at least one upper case letter A-Z. [doc] [play]
- <big>IsAlpha</big> : checks if the string contains only letters (a-zA-Z). [doc] [play]
- <big>IsAllUpper</big> : check if the string is all upper case letters A-Z. [doc] [play]
- <big>IsAllLower</big> : check if the string is all lower case letters a-z. [doc] [play]
- <big>IsBase64</big> : check if the string is base64 string. [doc] [play]
- <big>IsChineseMobile</big> : check if the string is chinese mobile number. [doc] [play]
- <big>IsChineseIdNum</big> : check if the string is chinese id card. [doc] [play]
- <big>IsChinesePhone</big> : check if the string is chinese phone number.(xxx-xxxxxxxx or xxxx-xxxxxxx.) [doc] [play]
- <big>IsCreditCard</big> : check if the string is credit card. [doc] [play]
- <big>IsDns</big> : check if the string is dns. [doc] [play]
- <big>IsEmail</big> : check if the string is a email address. [doc] [play]
- <big>IsEmptyString</big> : check if the string is empty. [doc] [play]
- <big>IsFloat</big> : check if the value is float(float32, float34) or not. [doc] [play]
- <big>IsFloatStr</big> : check if the string can convert to a float. [doc] [play]
- <big>IsNumber</big> : check if the value is number(integer, float) or not. [doc] [play]
- <big>IsNumberStr</big> : check if the string can convert to a number. [doc] [play]
- <big>IsJSON</big> : check if the string is valid JSON. [doc] [play]
- <big>IsRegexMatch</big> : check if the string match the regexp. [doc] [play]
- <big>IsInt</big> : check if the string can convert to a number. [doc] [play]
- <big>IsIntStr</big> : check if the string can convert to a integer. [doc] [play]
- <big>IsIp</big> : check if the string is ip. [doc] [play]
- <big>IsIpV4</big> : check if the string is ipv4. [doc] [play]
- <big>IsIpV6</big> : check if the string is ipv6. [doc] [play]
- <big>IsStrongPassword</big> : check if the string is strong password. [doc] [play]
- <big>IsUrl</big> : check if the string is url. [doc] [play]
- <big>IsWeakPassword</big> : check if the string is weak password. [doc] [play]
- <big>IsZeroValue</big> : check if value is a zero value. [doc] [play]
- <big>IsGBK</big> : check if data encoding is gbk. [doc] [play]
- <big>IsASCII</big> : checks if string is all ASCII char. [doc] [play]
- <big>IsPrintable</big> : checks if string is all printable chars. [doc] [play]
- <big>IsBin</big> : check if a give string is a valid binary value or not. [doc] [play]
- <big>IsHex</big> : check if a give string is a valid hexadecimal value or not. [doc] [play]
- <big>IsBase64URL</big> : check if a give string is a valid URL-safe Base64 encoded string. [doc] [play]
- <big>IsJWT</big> : check if a give string is a valid JSON Web Token (JWT). [doc] [play]
- <big>IsVisa</big> : check if a give string is a valid visa card number or not. [doc] [play]
- <big>IsMasterCard</big> : check if a give string is a valid master card number or not. [doc] [play]
- <big>IsAmericanExpress</big> : check if a give string is a valid american expression card number or not. [doc] [play]
- <big>IsUnionPay</big> : check if a give string is a valid union pay number or not. [doc] [play]
- <big>IsChinaUnionPay</big> : check if a give string is a valid china union pay number or not. [doc] [play]
import "github.com/duke-git/lancet/v2/xerror"
Function list:
- <big>New</big> : creates a new XError pointer instance with message. [doc] [play]
- <big>Wrap</big> : creates a new XError pointer instance based on error object, and add message. [doc] [play]
- <big>Unwrap</big> : returns unwrapped XError from err by errors.As. If no XError, returns nil. [doc] [play]
- <big>XError_Wrap</big> : creates a new XError and copy message and id to new one. [doc] [play]
- <big>XError_Unwrap</big> : Compatible with github.com/pkg/errors. [doc] [play]
- <big>XError_With</big> : adds key and value related to the XError object. [doc] [play]
- <big>XError_Id</big> : sets XError object id to check equality in XError.Is. [doc] [play]
- <big>XError_Is</big> : checks if target error is XError and Error.id of two errors are matched. [doc] [play]
- <big>XError_Values</big> : returns map of key and value that is set by XError.With function. [doc] [play]
- <big>XError_StackTrace</big> : returns stack trace which is compatible with pkg/errors. [doc] [play]
- <big>XError_Info</big> : returns information of xerror, which can be printed. [doc] [play]
- <big>XError_Error</big> : implements standard error interface. [doc] [play]
- <big>TryUnwrap</big> : check if err is nil then it returns a valid value. If err is not nil, TryUnwrap panics with err. [doc] [play]
How to Contribute
Contribution Guide
Contributors
Thank you to all the people who contributed to lancet!
<a href="https://github.com/duke-git/lancet/graphs/contributors"> <img src="https://contrib.rocks/image?repo=duke-git/lancet" /> </a>