Skip to content

Commit

Permalink
1.0.0 lets goooo
Browse files Browse the repository at this point in the history
  • Loading branch information
ELI7VH committed Jan 4, 2025
1 parent 1f53b0f commit 91600d0
Show file tree
Hide file tree
Showing 11 changed files with 4,132 additions and 7,048 deletions.
8 changes: 8 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('ts-jest').JestConfigWithTsJest} **/
module.exports = {
testEnvironment: "node",
testMatch: ["**/*.spec.ts"],
transform: {
"^.+.tsx?$": ["ts-jest", {}],
},
};
10,984 changes: 4,015 additions & 6,969 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dank-inc/lewps",
"version": "0.10.1",
"version": "1.0.0",
"author": "Elijah Lucian",
"description": "Some dank loop functions!",
"repository": {
Expand All @@ -27,8 +27,10 @@
"test": "jest"
},
"devDependencies": {
"ts-node": "^9.1.1",
"typescript": "^4.2.3",
"jest": "^26.6.3"
"@types/jest": "^29.5.14",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.7.2"
}
}
6 changes: 6 additions & 0 deletions src/lib/lewperz/forI.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
type ForICallback<T> = (item: T, i: number, u: number) => {};
type ForIOpts = {};

/**
* Iterates over an array and calls a callback function for each element
* @param arr The array to iterate over
* @param fn Callback function
* @param opts Optional options object
*/
export const forI = <T>(arr: T[], fn: ForICallback<T>, opts?: ForIOpts) => {
for (let i = 0; i < arr.length; i++) fn(arr[i], i, i / arr.length);
};
6 changes: 6 additions & 0 deletions src/lib/lewperz/forN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ type Opts = {
type: "lteq" | "lt" | "rev";
};

/**
* Iterates over a range of numbers and calls a callback function for each number
* @param n The size of the range
* @param fn Callback function
* @param opts Optional options object
*/
export const forN = (n: number, fn: ForNCallback, opts?: Opts) => {
if (!opts || opts?.type === "lt") {
for (let i = 0; i < n; i++) fn(i, i / (n - 1));
Expand Down
6 changes: 6 additions & 0 deletions src/lib/lewperz/forU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ type Options = {
end: number;
};

/**
* Iterates over a range of numbers and calls a callback function for each number
* @param steps The size of the range
* @param fn Callback function
* @param opts Optional options object
*/
export const forU = (steps: number, fn: ForUCallback, opts?: Options) => {
const start = opts?.start || 0;
const end = opts?.end || 1;
Expand Down
24 changes: 24 additions & 0 deletions src/lib/lewperz/lewpers.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { forI } from "./forI";
import { forN } from "./forN";
import { forU } from "./forU";

test("do the thing", () => {
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const result: number[] = [];
forI(arr, (i) => result.push(i));
expect(result).toEqual(arr);
});

test("do the thing", () => {
const result: number[] = [];
forN(10, (i) => result.push(i));
expect(result).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
});

test("do the thing", () => {
const result: number[] = [];
forU(10, (i) => result.push(i));
expect(result).toEqual([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]);
});

// todo deeper tests for complicated shit
7 changes: 0 additions & 7 deletions src/lib/mapperz/map.spec.js

This file was deleted.

13 changes: 13 additions & 0 deletions src/lib/mapperz/map.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { mapU, mapI, mapXY } from "./map";

test("do the thing", () => {
expect(mapU(10, () => {}).length).toBe(10);
});

test("do the thing", () => {
expect(mapI(10, () => {}).length).toBe(10);
});

test("do the thing", () => {
expect(mapXY(10, 10, () => {}).length).toBe(100);
});
38 changes: 38 additions & 0 deletions src/lib/mapperz/map.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import { forN } from "../lewperz/forN";
import { forU } from "../lewperz/forU";

/**
* Creates an array of cloned objects with incremented property values
* @template T - Type of the object to clone
* @param {T} thing - The object to clone
* @param {number} n - Number of clones to create
* @param {keyof T} property - Property to increment in each clone
* @returns {T[]} Array of cloned objects
*/
export const cloneU = <T>(thing: T, n: number, property: keyof T): T[] => {
const arr: T[] = [];
forU(n, (u) => arr.push({ ...thing, [property]: u }));
return arr;
};

/**
* Creates an array of cloned objects with custom modifications
* @template T - Type of the object to clone
* @param {T} thing - The object to clone
* @param {number} n - Number of clones to create
* @param {(u: number) => Partial<T>} cb - Callback function to modify each clone
* @returns {T[]} Array of modified clones
*/
export const cloneMap = <T>(
thing: T,
n: number,
Expand All @@ -21,18 +37,40 @@ export const cloneMap = <T>(
return arr;
};

/**
* Maps a range of numbers to an array using a callback function
* @template T - Type of the output array elements
* @param {number} n - Size of the range
* @param {(u: number) => T} cb - Mapping function
* @returns {T[]} Mapped array
*/
export const mapU = <T>(n: number, cb: (u: number) => T): T[] => {
const arr: T[] = [];
forU(n, (u) => arr.push(cb(u)));
return arr;
};

/**
* Maps a range of indices to an array using a callback function
* @template T - Type of the output array elements
* @param {number} n - Size of the range
* @param {(i: number) => T} cb - Mapping function
* @returns {T[]} Mapped array
*/
export const mapI = <T>(n: number, cb: (i: number) => T): T[] => {
const arr: T[] = [];
forN(n, (i) => arr.push(cb(i)));
return arr;
};

/**
* Maps a 2D coordinate space to a 1D array using a callback function
* @template T - Type of the output array elements
* @param {number} x - Width of the coordinate space
* @param {number} y - Height of the coordinate space
* @param {(u: number, v: number) => T} cb - Mapping function
* @returns {T[]} Mapped array
*/
export const mapXY = <T>(
x: number,
y: number,
Expand Down
78 changes: 10 additions & 68 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,73 +1,15 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */

/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,

// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
"declaration": true /* Generates corresponding '.d.ts' file. */,
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "lib" /* Redirect output structure to the directory. */,
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
"strictNullChecks": true /* Enable strict null checks. */,
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */

/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */

/* Advanced Options */
"skipLibCheck": true /* Skip type checking of declaration files. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
"target": "es5",
"module": "commonjs",
"declaration": true,
"outDir": "lib",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"exclude": ["src/playground.ts"]
}

0 comments on commit 91600d0

Please sign in to comment.