billy-herrington-utils 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +45 -32
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -14,35 +14,48 @@
14
14
  npm i billy-herrington-utils
15
15
  ```
16
16
 
17
- ## utils:
18
- * stringToWords
19
- * sanitizeStr
20
- * timeToSeconds
21
- * parseCSSUrl
22
- * parseDataParams
23
- * parseIntegerOr
24
- * Observer
25
- * LazyImgLoader
26
- * circularShift
27
- * MOBILE_UA
28
- * fetchHtml
29
- * fetchText
30
- * fetchWith
31
- * objectToFormData
32
- * Tick
33
- * listenEvents
34
- * parseDom
35
- * copyAttributes
36
- * downloader
37
- * findNextSibling
38
- * getAllUniqueParents
39
- * replaceElementTag
40
- * waitForElementExists
41
- * watchDomChangesWithThrottle
42
- * watchElementChildrenCount
43
- * isMob
44
- * computeAsyncOneAtTime
45
- * SyncPull
46
- * wait
47
- * chunks
48
- * range
17
+ **A comprehensive collection of utility 🛠️ functions to make dungeon life easier.**
18
+
19
+ **Key features:**
20
+
21
+ * **String manipulation:** Easily parse, sanitize, and convert strings.
22
+ * **Time and date:** Work with time and date values effortlessly.
23
+ * **DOM manipulation:** Interact with DOM elements like a pro.
24
+ * **Networking:** Make HTTP requests and handle data with ease.
25
+ * **Miscellaneous:** A variety of other useful functions for common tasks.
26
+
27
+ ## **Documentation**
28
+
29
+ | Function | Short Explanation | Input Parameters | Example Input/Output or Usage |
30
+ |---|---|---|---|
31
+ | `stringToWords(s)` | Splits a string into an array of words. | `s: string` | `stringToWords("Hello, world!")` -> `["hello", "world"]` |
32
+ | `sanitizeStr(s)` | Sanitizes a string by removing newlines, tabs, and extra spaces. | `s: string` | `sanitizeStr("Hello\nWorld\t")` -> `hello world` |
33
+ | `timeToSeconds(timeStr)` | Converts a time string to seconds. | `timeStr: string` | `timeToSeconds("1h30m")` -> `5400` |
34
+ | `parseIntegerOr(value, defaultValue)` | Parses a string as an integer. | `value: string`, `defaultValue: number` | `parseIntegerOr("10", 0)` -> `10`, `parseIntegerOr("abc", 0)` -> `0` |
35
+ | `parseDataParams(str)` | Parses a string containing data parameters into an object. | `str: string` | `parseDataParams("param1:value1;param2:value2")` -> `{ param1: "value1", param2: "value2" }` |
36
+ | `parseCSSUrl(cssUrl)` | Extracts the URL from a CSS `url()` declaration. | `cssUrl: string` | `parseCSSUrl("url('https://example.com/image.jpg')")` -> `https://example.com/image.jpg` |
37
+ | `Observer` | A class for observing elements and triggering callbacks when they intersect with the viewport. | N/A | `const observer = new Observer((target) => { console.log(target); }); observer.observe(element);` |
38
+ | `LazyImgLoader` | A class for lazy loading images. | N/A | `const lazyLoader = new LazyImgLoader(); lazyLoader.lazify(element, image, imageSrc);` |
39
+ | `circularShift(value, max, shift)` | Performs a circular shift on a number. | `value: number`, `max: number = 6`, `shift: number = 1` | `circularShift(5, 10, 2)` -> `7` |
40
+ | `parseDom(html)` | Parses HTML into a DOM element. | `html: string` | `const element = parseDom("<div>Hello</div>");` |
41
+ | `copyAttributes(target, source)` | Copies attributes from one DOM element to another. | `target: HTMLElement`, `source: HTMLElement` | `copyAttributes(targetElement, sourceElement);` |
42
+ | `replaceElementTag(element, tagName)` | Replaces a DOM element with a new element of a different tag. | `element: HTMLElement`, `tagName: string` | `replaceElementTag(element, "span");` |
43
+ | `getAllUniqueParents(elements)` | Gets all unique parent elements of a list of elements. | `elements: HTMLElement[]` | `const parents = getAllUniqueParents(elements);` |
44
+ | `findNextSibling(element)` | Finds the next sibling element of a given element. | `element: HTMLElement` | `const nextSibling = findNextSibling(element);` |
45
+ | `waitForElementExists(parent, selector, callback)` | Waits for an element to exist within a parent element and then calls a callback. | `parent: HTMLElement`, `selector: string`, `callback: (element: HTMLElement) => void` | `waitForElementExists(container, ".target-element", (element) => { ... });` |
46
+ | `watchElementChildrenCount(element, callback)` | Watches for changes in the number of children of an element and calls a callback. | `element: HTMLElement`, `callback: (observer: MutationObserver, count: number) => void` | `watchElementChildrenCount(element, (observer, count) => { ... });` |
47
+ | `watchDomChangesWithThrottle(element, callback, throttle = 1e3, options = { childList: true, subtree: true, attributes: true })` | Watches for DOM changes within an element and calls a callback with throttling. | `element: HTMLElement`, `callback: (mutationList: MutationRecord[]) => void`, `throttle?: number`, `options?: MutationObserverInit` | `watchDomChangesWithThrottle(element, (mutationList) => { ... });` |
48
+ | `downloader(options)` | Creates a download button for a video element. | `options: { button: string, append?: string, after?: string, cbBefore?: () => void }` | `downloader({ button: "#download-button" });` |
49
+ | `MOBILE_UA` | A constant containing a mobile user agent string. | N/A | `console.log(MOBILE_UA);` |
50
+ | `fetchWith(url, options)` | Fetches data from a URL. | `url: string`, `options: { html?: boolean, mobile?: boolean }` | `fetchWith("https://api.example.com/data", { html: true }).then((html) => { ... });` |
51
+ | `fetchHtml(url)` | Fetches HTML from a URL. | `url: string` | `fetchHtml("https://example.com/page.html").then((html) => { ... });` |
52
+ | `fetchText(url)` | Fetches text from a URL. | `url: string` | `fetchText("https://example.com/data.txt").then((text) => { ... });` |
53
+ | `objectToFormData(object)` | Converts an object to FormData. | `object: object` | `const formData = objectToFormData({ name: "John", age: 30 });` |
54
+ | `listenEvents(element, events, callback)` | Adds event listeners to a DOM element. | `element: HTMLElement`, `events: string[]`, `callback: (event: Event) => void` | `listenEvents(element, ["click", "mouseover"], (event) => { ... });` |
55
+ | `Tick(delay, startImmediate = true)` | A class for creating interval timers. | `delay: number`, `startImmediate?: boolean` | `const tick = new Tick(1000, false); tick.start(() => { ... });` |
56
+ | `isMob()` | Checks if the current device is a mobile device. | N/A | `if (isMob()) { ... }` |
57
+ | `computeAsyncOneAtTime(iterable)` | Executes asynchronous functions one at a time. | `iterable: Iterable<() => Promise<any>>` | `computeAsyncOneAtTime(asyncFunctions).then((results) => { ... });` |
58
+ | `wait(milliseconds)` | Waits for a given number of milliseconds. | `milliseconds: number` | `await wait(1000);` |
59
+ | `SyncPull` | A class for managing asynchronous tasks with priorities. | N/A | `const syncPull = new SyncPull(); syncPull.push(() => { ... });` |
60
+ | `chunks(arr, n)` | Splits an array into chunks of a given size. | `arr: Array<any>`, `n: number` | `const chunks = chunks([1, 2, 3, 4, 5], 2);` -> `[[1, 2], [3, 4], [5]]` |
61
+ | `range(start, end)` | Creates a range of numbers from `start` to `end` (inclusive). | `start: number`, `end: number` | `const numbers = range(1, 5);` -> `[1, 2, 3, 4, 5]` |
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "billy-herrington-utils",
3
3
  "description": "daddy told us not to be ashamed of our utils",
4
- "version": "1.1.2",
4
+ "version": "1.1.3",
5
5
  "license": "MIT",
6
6
  "keywords": ["utils", "observer", "dom", "fetch", "arrays", "typescript"],
7
7
  "author": "smartacephale atm.mormon@protonmail.com (https://github.com/smartacephale)",