Current Version: 2018 Download   Contact

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:

  1. GetArgStr(NAME, DEFAULT) - returns a string given in the URL
  2. GetArgInt(NAME, DEFAULT) - returns an integer specified in the URL
  3. isValidURL(URL) - returns true if the given URL contains valid characters
  4. isValidEmail(EMAIL) - returns true if the given email address has valid format
  5. isValidName(NAME) - returns true if the given string could be a person's name
  6. InitArray(SIZE) - creates an array full of zeros
  7. charCodeArray(STRING) - converts string to an array of ASCII codes (See Example)
  8. fromCharCodeArray(ARRAY) - assembles a string from an array of ASCII codes
  9. MergeArray(A, B) - copies B into A without creating duplicates
  10. Group(S, N) - creates an array from string by splitting it into equal size chunks
  11. ExtractDuplicates(A) - sorts an array and removes duplicates
  12. FindInArray(S, A) - looks for a string anywhere in an array
  13. LookUp(S, A) - finds array element that exactly matches string
  14. Swap(A, x, y) - swaps two array values
  15. SortBy(ARRAY, ROW) - sorts a 2-dimensional array by row
  16. SortArrays(ARRAY1, ARRAY2...) - sorts several arrays using qsort algorithm
  17. toHex(D) - converts a number to two-digit hexadecimal format
  18. toHexWord(N) - converts a number to four-digit hexadecimal format
  19. toBin(LONG) - converts a number to custom-length binary format
  20. Bin2Int(B) - converts a binary string to a 32-bit number
  21. Bin2Hex(B) - converts a binary string to a hex string
  22. Bin2Str(B) - converts a string of zeros and ones to a binary string
  23. Str2Bin(S) - converts a string to string of zeros and ones
  24. Str2Hex(S) - converts a string to hex numbers
  25. Hex2Bin(X) - converts a hex string to binary format
  26. Hex2Str(X) - converts a string of hex digits to binary string
  27. Hex2Int(X) - converts a hex string to a 32-bit number
  28. EncodeB64(S) - encodes a binary string to Base64 string
  29. DecodeB64(S) - decodes a Base64 string to binary string
  30. Repeat(S, N) - repeat a string N number of times
  31. Trim(T) - removes whitespace before and after text
  32. LTRIM$(T) - removes whitespace from the left of text
  33. RTRIM$(T) - removes whitespace from the right of text
  34. CollapseWhitespace(S) - converts double whitespace to single
  35. Truncate(T, MAXLEN) - cuts long strings and adds "..."
  36. CharAt(S, X) - similar to String.charAt()
  37. CharCodeAt(S, X) - similar to String.charCodeAt()
  38. isLetter(S) - returns true if it's a letter
  39. Between(S, L, R) - returns a string between two strings
  40. StrBefore(S, M) - returns whatever comes before string M
  41. StrAfter(S, M) - returns whatever comes after string M
  42. StrCount(S, M) - counts how many times one string occurs in another
  43. StartsWith(S, M) - returns true if a string starts with a certain pattern
  44. EndsWith(S, M) - returns true if a string ends with a certain pattern
  45. EnsureStart(S, X) - makes sure that string starts with a certain pattern
  46. EnsureEnd(S, X) - makes sure that string ends with a certain pattern
  47. isLettersOnly(S) - returns true if string consists of letters only
  48. isAlphaNumberic(S) - returns true if string contains letters and numbers only
  49. isEmpty(S) - returns true if string is full of whitespaces or is empty/null/undefined
  50. isLower(S) - returns true if string is already converted to lowercase
  51. isUpper(S) - returns true if string is already converted to uppercase
  52. isNumeric(S) - returns true if string contains digits only
  53. SplitAt(S, X) - splits a string at a certain position
  54. SplitAB(S, P) - splits a string along a certain pattern
  55. LastSplitAB(S, P) - splits a string along a certain pattern
  56. StrReplace(S, A, B) - replaces all instances of string A with B
  57. StrReplaceAll(S, A, B) - same as above but uses regex
  58. StrReverse(S) - reverses characters of string
  59. StrLeft(S, N) - returns the first part of a string
  60. StrRight(S, N) - returns the last few characters of a string
  61. Split(TEXT) - splits a string along comma, whitespace, semicolon, etc.
  62. SplitLines(S) - splits a string along new-line characters
  63. LetterCount(S) - counts number of vowels and/or consonants in a string
  64. XOR(STRING, PW) - simple encoder using XOR
  65. Capitalize(S) - capitalizes a string
  66. TitleCase(S) - capitalizes the first letter of every word
  67. SentenceCase(S) - capitalizes the first letter of each sentence
  68. EveryOther(S) - capitalizes every other letter of string
  69. ReverseCase(S) - reverses uppercase letters with lowercase and vice versa
  70. MatchWord(S, W) - capitalizes every instance of a word in a string
  71. StrInsert(A, B, N) - inserts one string into another
  72. strFilter(S, ALLOWED) - removes "foreign characters" from a string
  73. CHR$(C) - same as String.fromCharCode(C)
  74. ASC(S) - returns the first character code of a string
  75. CharCount(S) - counts how many times each type of character occurs in a string
  76. ShowCount(S) - prints the results of the CharCount() function
  77. charRange(MIN, MAX) - creates a character set such as "ABC"
  78. regularCharSet(S) - returns a list of characters that occur in a string
  79. inverseCharSet(S) - returns a list of characters that do not occur in a string
  80. isFromCharSet(S, KNOWN) - returns true if a string is made up of certain bytes
  81. ConvertCharSet(S, OLDSET, NEWSET) - replaces characters in a string
  82. EncodeURL(S) - converts a binary string to an URL-safe string
  83. DecodeURL(S) - converts an URL argument to a binary string
  84. EncodeHTML(S) - converts a binary string to HTML-safe string
  85. DecodeHTML(S) - converts safe string to binary string
  86. isHex(S) - returns true if it's a valid hex number
  87. isDec(S) - returns true if its a natural decimal number
  88. isBin(S) - returns true if it's a binary number
  89. ForceHex(S) - removes non-hex digits from a string
  90. ForceDec(S) - removes non-decimal digits from a string
  91. ForceBin(S) - removes everything except ones and zeros
  92. FIX(X, N) - forces a number to be X bytes long
  93. lastNumber(s) - extracts the last whole number from string
  94. DiscardHighBit(S) - removes the high bit from a binary string
  95. InsertHighBit(S) - inserts the high bit into a binary string
  96. now() - returns the number of milliseconds since Jan 1970.
  97. M() - returns the milliseconds from the current time
  98. TimeAgo(T) - returns a text string that says "X minutes ago"
  99. CreateTimeAgo(OBJECT_ID, T) - creates a live string that automatically updates itself and shows how long ago something happened
  100. toColor(R, G, B) - converts 3 decimal numbers to 6-digit hex code
  101. GetRGB(C) - breaks down a 6-digit hex code into decimal numbers
  102. InvertColor(C) - inverts a color
  103. GetColorShades(C1, C2, N) - returns a transision array of colors
  104. CalculateColorGain(C1, C2, N) - calculates color change between two colors
  105. WriteInColor(S, C1, C2) - prints a text where each letter is printed in a different color from C1 to C2
  106. 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)
  107. 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)
  108. ColorGain(C, RG, GG, BG) - increase or decrease brightness of a color
  109. WGET(URL) - downloads a file from the internet
  110. AddTimer(FUNC, DELAY, REP) - schedules a function to execute at regular intervals
  111. Timer(E) - measure the time it takes to do a certain operation
  112. ShowTimer() - displays the results collected by Timer()
  113. ROR8(BYTE, N) - performs bitwise rotate of a byte left or right
  114. ROR16(WORD, N) - performs bitwise rotate on a 16-bit word
  115. ROR32(LONG, N) - performs bitwise rotate on a 32-bit long
  116. RORS(S, N, StartBit, EndBit) - rotates a string segment
  117. ReadBIT(ARRAY, BIT_INDEX) - returns one bit from an array of long ints
  118. ReadBYTE(ARRAY, BYTE_INDEX) - returns one byte from an array of long ints
  119. WriteBIT(ARRAY, BIT_INDEX, BIT) - changes one bit in an array of long ints
  120. WriteBYTE(ARRAY, BYTE_INDEX, BYTE) - changes one byte in an array of ints
  121. WriteWORD(ARRAY, WORD_INDEX, WORD) - changes one word in an array of ints
  122. WriteSTRING(ARRAY, BYTE_INDEX, STRING) - writes a string into an array of ints
  123. RND(SALT) - creates a random number
  124. RNDL(SALT) - returns a 14-digit random number between 0 and 1
  125. RNDW(SALT) - returns a word-size random number between 0 and 65536
  126. CRC(S) - returns a simple 4-byte CRC
  127. XCrypt(S, P) - encrypts a string using the XOR operator and randomized password
  128. Shuffle(ARRAY, UNDO) - shuffles an array or puts elements back in original order
  129. AddSalt(S) - doubles the size of input string and returns a new string
  130. RemoveSalt(S) - removes characters added by AddSalt()
  131. SetCookie(NAME, VALUE) - creates a cookie
  132. GetCookie(NAME) - retrieves a cookie
  133. DeleteCookie(NAME) - deletes one cookie
  134. DeleteAllCookies() - deletes all cookies
  135. DeleteItem(NAME) - deletes an item from localStorage
  136. DeleteAllItems() - deletes everything from localStorage
  137. SetXCookie(NAME, VALUE) - stores an "encrypted" cookie
  138. GetXCookie(NAME) - retrieves an "encrypted" cookie
  139. SetValue(NAME, VALUE) - saves a value in a cookie AND localStorage
  140. GetValue(NAME) - retrieves a value from a cookie or localStorage
  141. CookieTest() - returns true if cookies are working
  142. StorageTest() - returns true if localStorage is working
  143. PRINT(L) - allows user to buffer HTML output
  144. FLUSH() - uses document.write to flush the buffer
  145. SetOpacity(E, A) - changes the transparency of an object
  146. SetObjCoords(E, LEFT, TOP) - causes an object to float and changes coordinates
  147. FadeIn(E) - fades an element into view
  148. FadeOut(E) - fades out an element
  149. DrawBox(X1, Y1, W, H, C) - draws a box anywhere
  150. DrawFrame(X1, Y1, W, H, BW, C) - draws a frame
  151. DrawPixel(X, Y, C) - changes color of a pixel
  152. DrawLine(W, T, C, M) - draws a horizontal line
  153. DrawCover(X, Y, W, H) - places a transparent image over an area
  154. DrawNiceBox(C1, C2, T, C) - draws a colorful box

Download ZLIB.JS