ZLIB JavaScript Library
WHAT IS ZLIB... ZLIB.JS is a single file JavaScript library that contains string functions, array functions, number converters, and various other things such as browser and mobile device detection, encryption, random number generation, color converters, task manager, benchmark tools, binary rotate, binary array access, cookie and localStorage functions, basic AJAX, and some basic drawing functionality that is compatible with older browsers like IE6.
HOW IT BEGAN... I started learning JavaScript programming as a hobby when I was 18. I copied JavaScript functions from other websites and modified the code slightly to see what happens... Over the years, I wrote a lot of JavaScript on my own, and I decided to combine my various helper functions into one file. That's how ZLIB was born. None of this was a paid project. I created this in my spare time. Since my name is Zsolt, I named this package "ZLIB.JS."
THE GOAL... My goal is to make websites that are fully compatible with older web browsers. I hate when a website says, "You need to upgrade your web browser." Therefore, ZLIB is compatible with IE6, Safari 5.1.7, Opera 7.54, K-Meleon 1.5.4, QupZilla 1.8.6, and of course, all of Chrome and Firefox. Windows XP comes with IE6, so if some visitors are using XP, they should have no glitches whatsoever. My second priority is speed. I test some of my functions to make sure they run as fast as possible. For example, one of the functions I wrote Str2Hex() runs faster than the builtin JavaScript function .toString(16).
FUTURE OF ZLIB... As long as I live and I am healthy and computer programming is still my hobby, I will keep improving the ZLIB library. I may add functionality to it over time. Since future editions/versions of ZLIB may have major differences, I encouarge you to download a copy of ZLIB and use it in your website instead of linking to it from this site. Besides, this site might not stay here always. I may move this page to a different domain. You don't want your website to quit working all of a sudden.
ZLIB COMPATIBILITY... Future versions of ZLIB might not be fully compatible with earlier versions which is another reason why you should make a copy for yourself instead always using the newest version.
WHY I LOVE JAVASCRIPT... I think, JavaScript is a beautiful language. Its simplicity reminds me of QBasic, which was the first programming language I learned. Of course, JavaScript is somewhat similar to C/C++ and it has elements of Perl in it, which is also one of my favorite languages. JavaScript combines all the good into one language. What makes it so awesome is that it runs on all devices. It doesn't matter whether you have a Kindle Fire, an Apple iPhone or iMac, Windows XP/7/10 or an Android tablet or a WebTV -- JavaScript runs on ALL computers.
ZLIB API Here is a list of all functions in the 2018 Edition of ZLIB:
- GetArgStr(NAME, DEFAULT) - returns a string given in the URL
- GetArgInt(NAME, DEFAULT) - returns an integer specified in the URL
- isValidURL(URL) - returns true if the given URL contains valid characters
- isValidEmail(EMAIL) - returns true if the given email address has valid format
- isValidName(NAME) - returns true if the given string could be a person's name
- InitArray(SIZE) - creates an array full of zeros
- charCodeArray(STRING) - converts string to an array of ASCII codes (See Example)
- fromCharCodeArray(ARRAY) - assembles a string from an array of ASCII codes
- MergeArray(A, B) - copies B into A without creating duplicates
- Group(S, N) - creates an array from string by splitting it into equal size chunks
- ExtractDuplicates(A) - sorts an array and removes duplicates
- FindInArray(S, A) - looks for a string anywhere in an array
- LookUp(S, A) - finds array element that exactly matches string
- Swap(A, x, y) - swaps two array values
- SortBy(ARRAY, ROW) - sorts a 2-dimensional array by row
- SortArrays(ARRAY1, ARRAY2...) - sorts several arrays using qsort algorithm
- toHex(D) - converts a number to two-digit hexadecimal format
- toHexWord(N) - converts a number to four-digit hexadecimal format
- toBin(LONG) - converts a number to custom-length binary format
- Bin2Int(B) - converts a binary string to a 32-bit number
- Bin2Hex(B) - converts a binary string to a hex string
- Bin2Str(B) - converts a string of zeros and ones to a binary string
- Str2Bin(S) - converts a string to string of zeros and ones
- Str2Hex(S) - converts a string to hex numbers
- Hex2Bin(X) - converts a hex string to binary format
- Hex2Str(X) - converts a string of hex digits to binary string
- Hex2Int(X) - converts a hex string to a 32-bit number
- EncodeB64(S) - encodes a binary string to Base64 string
- DecodeB64(S) - decodes a Base64 string to binary string
- Repeat(S, N) - repeat a string N number of times
- Trim(T) - removes whitespace before and after text
- LTRIM$(T) - removes whitespace from the left of text
- RTRIM$(T) - removes whitespace from the right of text
- CollapseWhitespace(S) - converts double whitespace to single
- Truncate(T, MAXLEN) - cuts long strings and adds "..."
- CharAt(S, X) - similar to String.charAt()
- CharCodeAt(S, X) - similar to String.charCodeAt()
- isLetter(S) - returns true if it's a letter
- Between(S, L, R) - returns a string between two strings
- StrBefore(S, M) - returns whatever comes before string M
- StrAfter(S, M) - returns whatever comes after string M
- StrCount(S, M) - counts how many times one string occurs in another
- StartsWith(S, M) - returns true if a string starts with a certain pattern
- EndsWith(S, M) - returns true if a string ends with a certain pattern
- EnsureStart(S, X) - makes sure that string starts with a certain pattern
- EnsureEnd(S, X) - makes sure that string ends with a certain pattern
- isLettersOnly(S) - returns true if string consists of letters only
- isAlphaNumberic(S) - returns true if string contains letters and numbers only
- isEmpty(S) - returns true if string is full of whitespaces or is empty/null/undefined
- isLower(S) - returns true if string is already converted to lowercase
- isUpper(S) - returns true if string is already converted to uppercase
- isNumeric(S) - returns true if string contains digits only
- SplitAt(S, X) - splits a string at a certain position
- SplitAB(S, P) - splits a string along a certain pattern
- LastSplitAB(S, P) - splits a string along a certain pattern
- StrReplace(S, A, B) - replaces all instances of string A with B
- StrReplaceAll(S, A, B) - same as above but uses regex
- StrReverse(S) - reverses characters of string
- StrLeft(S, N) - returns the first part of a string
- StrRight(S, N) - returns the last few characters of a string
- Split(TEXT) - splits a string along comma, whitespace, semicolon, etc.
- SplitLines(S) - splits a string along new-line characters
- LetterCount(S) - counts number of vowels and/or consonants in a string
- XOR(STRING, PW) - simple encoder using XOR
- Capitalize(S) - capitalizes a string
- TitleCase(S) - capitalizes the first letter of every word
- SentenceCase(S) - capitalizes the first letter of each sentence
- EveryOther(S) - capitalizes every other letter of string
- ReverseCase(S) - reverses uppercase letters with lowercase and vice versa
- MatchWord(S, W) - capitalizes every instance of a word in a string
- StrInsert(A, B, N) - inserts one string into another
- strFilter(S, ALLOWED) - removes "foreign characters" from a string
- CHR$(C) - same as String.fromCharCode(C)
- ASC(S) - returns the first character code of a string
- CharCount(S) - counts how many times each type of character occurs in a string
- ShowCount(S) - prints the results of the CharCount() function
- charRange(MIN, MAX) - creates a character set such as "ABC"
- regularCharSet(S) - returns a list of characters that occur in a string
- inverseCharSet(S) - returns a list of characters that do not occur in a string
- isFromCharSet(S, KNOWN) - returns true if a string is made up of certain bytes
- ConvertCharSet(S, OLDSET, NEWSET) - replaces characters in a string
- EncodeURL(S) - converts a binary string to an URL-safe string
- DecodeURL(S) - converts an URL argument to a binary string
- EncodeHTML(S) - converts a binary string to HTML-safe string
- DecodeHTML(S) - converts safe string to binary string
- isHex(S) - returns true if it's a valid hex number
- isDec(S) - returns true if its a natural decimal number
- isBin(S) - returns true if it's a binary number
- ForceHex(S) - removes non-hex digits from a string
- ForceDec(S) - removes non-decimal digits from a string
- ForceBin(S) - removes everything except ones and zeros
- FIX(X, N) - forces a number to be X bytes long
- lastNumber(s) - extracts the last whole number from string
- DiscardHighBit(S) - removes the high bit from a binary string
- InsertHighBit(S) - inserts the high bit into a binary string
- now() - returns the number of milliseconds since Jan 1970.
- M() - returns the milliseconds from the current time
- TimeAgo(T) - returns a text string that says "X minutes ago"
- CreateTimeAgo(OBJECT_ID, T) - creates a live string that automatically updates itself and shows how long ago something happened
- toColor(R, G, B) - converts 3 decimal numbers to 6-digit hex code
- GetRGB(C) - breaks down a 6-digit hex code into decimal numbers
- InvertColor(C) - inverts a color
- GetColorShades(C1, C2, N) - returns a transision array of colors
- CalculateColorGain(C1, C2, N) - calculates color change between two colors
- WriteInColor(S, C1, C2) - prints a text where each letter is printed in a different color from C1 to C2
- HSL2RGB(H, S, L) - converts Hue, Saturation, and Luminance to RGB values. (Note: I copied the calculations from www.rapidtables.com/convert/color/hsv-to-rgb.htm, so this is not something that I created on my own)
- RGB2HSL(R, G, B) - converts RGB values to HSL format (Note: Again, this is not my work. I copied this algorithm from www.javascripter.net/faq/rgb2hsv.htm)
- ColorGain(C, RG, GG, BG) - increase or decrease brightness of a color
- WGET(URL) - downloads a file from the internet
- AddTimer(FUNC, DELAY, REP) - schedules a function to execute at regular intervals
- Timer(E) - measure the time it takes to do a certain operation
- ShowTimer() - displays the results collected by Timer()
- ROR8(BYTE, N) - performs bitwise rotate of a byte left or right
- ROR16(WORD, N) - performs bitwise rotate on a 16-bit word
- ROR32(LONG, N) - performs bitwise rotate on a 32-bit long
- RORS(S, N, StartBit, EndBit) - rotates a string segment
- ReadBIT(ARRAY, BIT_INDEX) - returns one bit from an array of long ints
- ReadBYTE(ARRAY, BYTE_INDEX) - returns one byte from an array of long ints
- WriteBIT(ARRAY, BIT_INDEX, BIT) - changes one bit in an array of long ints
- WriteBYTE(ARRAY, BYTE_INDEX, BYTE) - changes one byte in an array of ints
- WriteWORD(ARRAY, WORD_INDEX, WORD) - changes one word in an array of ints
- WriteSTRING(ARRAY, BYTE_INDEX, STRING) - writes a string into an array of ints
- RND(SALT) - creates a random number
- RNDL(SALT) - returns a 14-digit random number between 0 and 1
- RNDW(SALT) - returns a word-size random number between 0 and 65536
- CRC(S) - returns a simple 4-byte CRC
- XCrypt(S, P) - encrypts a string using the XOR operator and randomized password
- Shuffle(ARRAY, UNDO) - shuffles an array or puts elements back in original order
- AddSalt(S) - doubles the size of input string and returns a new string
- RemoveSalt(S) - removes characters added by AddSalt()
- SetCookie(NAME, VALUE) - creates a cookie
- GetCookie(NAME) - retrieves a cookie
- DeleteCookie(NAME) - deletes one cookie
- DeleteAllCookies() - deletes all cookies
- DeleteItem(NAME) - deletes an item from localStorage
- DeleteAllItems() - deletes everything from localStorage
- SetXCookie(NAME, VALUE) - stores an "encrypted" cookie
- GetXCookie(NAME) - retrieves an "encrypted" cookie
- SetValue(NAME, VALUE) - saves a value in a cookie AND localStorage
- GetValue(NAME) - retrieves a value from a cookie or localStorage
- CookieTest() - returns true if cookies are working
- StorageTest() - returns true if localStorage is working
- PRINT(L) - allows user to buffer HTML output
- FLUSH() - uses document.write to flush the buffer
- SetOpacity(E, A) - changes the transparency of an object
- SetObjCoords(E, LEFT, TOP) - causes an object to float and changes coordinates
- FadeIn(E) - fades an element into view
- FadeOut(E) - fades out an element
- DrawBox(X1, Y1, W, H, C) - draws a box anywhere
- DrawFrame(X1, Y1, W, H, BW, C) - draws a frame
- DrawPixel(X, Y, C) - changes color of a pixel
- DrawLine(W, T, C, M) - draws a horizontal line
- DrawCover(X, Y, W, H) - places a transparent image over an area
- DrawNiceBox(C1, C2, T, C) - draws a colorful box
Download ZLIB.JS
|