Skip to content

Commit

Permalink
chore: Update helpers with cleaner comments and less dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
fourjuaneight authored Jan 7, 2025
1 parent 616044e commit 2100e17
Show file tree
Hide file tree
Showing 55 changed files with 181 additions and 631 deletions.
2 changes: 0 additions & 2 deletions templates/helpers/animationInterval.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/**
* Corss-browser, time perfect, animation interval.
* @function
*
* @param {number} ms when to ship animation; interval
* @param {AbortSignal} signal performant abort of interval
* @param {function} callback get time for next frame
* @return {void}
*/
export const animationInterval = (
ms: number,
Expand Down
5 changes: 0 additions & 5 deletions templates/helpers/arithmeticProgression.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/**
* Creates an array of numbers in the arithmetic progression, starting with the given positive integer and up to the specified limit.
* @function
*
* @param {number} number
* @param {number} limit
* @returns {number[]}
*/
export const arithmeticProgression = (
number: number,
Expand Down
6 changes: 0 additions & 6 deletions templates/helpers/arrayContainsObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import { deepCheck } from './objectsEqual';

/**
* Determine if object is found in given array.
* @function
*
* @param {array} arr array to lookup against
* @param {object} obj object to search for
*
* @returns {boolean} is obj in array
*/
export const arrayContainsObject = <A, O>(arr: A[], obj: O): boolean =>
arr.some((elem) => deepCheck(elem, obj));
7 changes: 0 additions & 7 deletions templates/helpers/arrayDiff.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
/**
* Diff two arrays of objects by key.
* @function
*
* @param {array} arr1 first array to compare
* @param {array} arr2 second array to comprare
* @param {string} key objecy key (in arrays) to compare against
*
* @returns {array} diff between two arrays
*/
export const arrayDiff = <A, B>(arr1: A[], arr2: B[], key: string): : any[] =>
arr1.filter((item1) => !arr2.some((item2) => item1[key] === item2[key]));
6 changes: 0 additions & 6 deletions templates/helpers/arrayToObject.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
/**
* Convert array to object sorted by given key value.
* @function
*
* @param {array} array raw data source
* @param {string} key kay-value to re-organize by
*
* @returns {object} record by title key
*/
export const arrayToObject = <A, T>(array: A[], key = "title"): Type => {
const initialValue = {};
Expand Down
8 changes: 0 additions & 8 deletions templates/helpers/arrayUniqueCount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ interface Aggregate {

/**
* Aggregates unique values in an array.
* @function
*
* @param {array} iterable array of items to count
* @returns {object} object with unique items and their count
*/
export const countUnique = (iterable: string[]) =>
iterable.reduce((acc: Aggregate, item) => {
Expand All @@ -18,10 +14,6 @@ export const countUnique = (iterable: string[]) =>
/**
* Aggregates unique values in an array.
* Sorted by count descending.
* @function
*
* @param {array} iterable array of items to count
* @returns {object} object with unique items and their count
*/
export const countUniqueSorted = (iterable: string[]) =>
Object.entries(countUnique(iterable))
Expand Down
87 changes: 0 additions & 87 deletions templates/helpers/assetsToSW.ts

This file was deleted.

6 changes: 0 additions & 6 deletions templates/helpers/binarySearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ const lessThan = (a: : string | number, b: : string | number): boolean => compar

/**
* Binary search implementation.
* @function
*
* @param {*[]} sortedArray
* @param {*} seekElement
*
* @return {number}
*/
export const binarySearch = <A>(sortedArray: A[], seekElement: : string | number): number => {
// These two indices will contain current array (sub-array) boundaries.
Expand Down
6 changes: 0 additions & 6 deletions templates/helpers/bufferToFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ const { writeFile } = promises;

/**
* Save buffer as local file.
* @function
*
* @param {Buffer} data media buffer to save
* @param {string} name file name
*
* @returns {Promise<void>}
*/
export const bufferToFile = async (data: Buffer, name: string): Promise<void> => {
try {
Expand Down
62 changes: 0 additions & 62 deletions templates/helpers/cacheAssets.ts

This file was deleted.

4 changes: 0 additions & 4 deletions templates/helpers/cleanObject.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/**
* Remove null or undefined values from an object.
* @function
*
* @param {*} obj entry object to cleanup
* @returns clean object
*/
export const cleanObject = <O, T>(obj: O): T =>
Object.fromEntries(
Expand Down
36 changes: 0 additions & 36 deletions templates/helpers/comparison.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
/**
* Default comparison function. It just assumes that "a" and "b" are strings or numbers.
* @function
*
* @param {(string|number)} a
* @param {(string|number)} b
*
* @returns {number}
*/
export const compare = (a: string | number, b: string | number): number => {
if (a === b) {
Expand All @@ -17,57 +11,27 @@ export const compare = (a: string | number, b: string | number): number => {

/**
* Checks if two variables are equal.
* @function
*
* @param {*} a
* @param {*} b
*
* @return {boolean}
*/
export const equal = <A, B>(a: A, b: B): boolean => compare(a, b) === 0;

/**
* Checks if variable "a" is less than "b".
* @function
*
* @param {*} a
* @param {*} b
*
* @return {boolean}
*/
export const lessThan = <A, B>(a: A, b: B): boolean => compare(a, b) < 0;

/**
* Checks if variable "a" is less than or equal to "b".
* @function
*
* @param {*} a
* @param {*} b
*
* @return {boolean}
*/
export const lessThanOrEqual = <A, B>(a: A, b: B): boolean =>
lessThan(a, b) || equal(a, b);

/**
* Checks if variable "a" is greater than "b".
* @function
*
* @param {*} a
* @param {*} b
*
* @return {boolean}
*/
export const greaterThan = <A, B>(a: A, b: B): boolean => compare(a, b) > 0;

/**
* Checks if variable "a" is greater than or equal to "b".
* @function
*
* @param {*} a
* @param {*} b
*
* @return {boolean}
*/
export const greaterThanOrEqual = <A, B>(a: A, b: B): boolean =>
greaterThan(a, b) || equal(a, b);
7 changes: 0 additions & 7 deletions templates/helpers/cookies.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/**
* Sets a cookie with an optional expiration time.
*
* @param name - The name of the cookie.
* @param value - The value of the cookie.
* @param expires - The expiration time in seconds or a specific Date object.
*/
export const setCookie = (
name: string,
Expand All @@ -29,9 +25,6 @@ export const setCookie = (

/**
* Retrieves the value of a specified cookie.
*
* @param name - The name of the cookie to retrieve.
* @returns The value of the cookie, or null if not found.
*/
export const getCookie = (name: string): string | null => {
const nameEQ = `${name}=`
Expand Down
5 changes: 0 additions & 5 deletions templates/helpers/countSubstrings.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/**
* Counts the occurrences of a substring in a given string.
* @function
*
* @param {string} str string to search
* @param {string} searchValue value to search for
* @returns {number} found occurrences
*/
export const countSubstrings = (str: string, searchValue: string): number => {
let count = 0;
Expand Down
5 changes: 0 additions & 5 deletions templates/helpers/createBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import { Readable } from 'stream';

/**
* Create buffer from readable stream.
* @function
* @async
*
* @param {Readable} stream
* @returns {Buffer} video buffer
*/
export const createBuffer = async (stream: Readable): Promise<Buffer> => {
const chunks = [];
Expand Down
7 changes: 1 addition & 6 deletions templates/helpers/dashToCamelCase.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/**
* Dashed string to camel case.
* @function
*
* @param {string} str dash separate string
*
* @returns {string} camelCased string
* Convert dashed string to camel case.
*/
export const dashToCamelCase = (str: string): string =>
str
Expand Down
Loading

0 comments on commit 2100e17

Please sign in to comment.