Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch release #22

Merged
merged 40 commits into from
Mar 6, 2024
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e7db04f
init
chalu Feb 15, 2024
0132918
get started with the implementation
chalu Feb 15, 2024
f6241ef
allow caller filter in elements with a match function
chalu Feb 15, 2024
9ea6c84
setup unit tests
chalu Feb 15, 2024
477c5df
add smoke tests for the list parameter
chalu Feb 15, 2024
a8513ce
add smoke tests for maxItems param
chalu Feb 15, 2024
87d8c36
add smoke tests for the match param
chalu Feb 15, 2024
9b41f0a
refactor param validation into a separate function
chalu Feb 15, 2024
3a9dfbf
add basic CI workflow
chalu Feb 15, 2024
72bf07d
re-add CI workflow file
chalu Feb 15, 2024
3795560
add catch all branch in CI workflow
chalu Feb 15, 2024
e2c42cd
try install pnpm before node in CI workflow
chalu Feb 15, 2024
7c81b61
attempt display test summary on GHA overview page
chalu Feb 15, 2024
18b2461
add TAP reporter for tests in CI
chalu Feb 15, 2024
15eada8
attempt junit reporter for summary in CI
chalu Feb 15, 2024
66f93e3
remove TAP reporter
chalu Feb 15, 2024
e1efbf2
improve setup for tests
chalu Feb 16, 2024
97db447
add matchers from jest-extended
chalu Feb 16, 2024
5aa4f84
add smoke tests
chalu Feb 16, 2024
ac99976
add festures tests
chalu Feb 16, 2024
ae39890
enforce code style with XO
chalu Feb 16, 2024
433c458
add pre-commit hook to run lint, build, and test scripts
chalu Feb 16, 2024
6c9f083
simplify pre-commit script
chalu Feb 16, 2024
c0646b8
add built files in dist folder
chalu Feb 16, 2024
ea42403
Merge pull request #5 from chalu/add-unit-tests
chalu Feb 16, 2024
abb0cd8
add docs and samples (#7)
chalu Feb 17, 2024
5c8e09d
Merge branch 'main' into dev
chalu Feb 17, 2024
6c301d0
Go publish (#9)
chalu Feb 18, 2024
2f62a5d
Merge branch 'main' into dev
chalu Feb 18, 2024
4dc022e
Go publish (#11)
chalu Feb 18, 2024
8d881d8
Merge branch 'main' into dev
chalu Feb 18, 2024
36d8a7c
Dry run publishing on dev (#13)
chalu Feb 18, 2024
2acd5cd
Dry run release (#14)
chalu Feb 18, 2024
d4dc284
Attempt release from GHA (#16)
chalu Feb 18, 2024
a0397ab
Atempt publish (#17)
chalu Feb 18, 2024
3b00a61
Attempt auto publish (#18)
chalu Feb 18, 2024
875ad62
Go public (#19)
chalu Feb 18, 2024
9f9b4c7
Merge branch 'main' into dev
chalu Feb 18, 2024
b79a13b
patch current release (#21)
chalu Mar 6, 2024
650925c
resolve conflicts with main
chalu Mar 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add built files in dist folder
chalu committed Feb 16, 2024
commit c0646b8790fd10a8d4b257f7ac3c3321f4f5e5c3
13 changes: 9 additions & 4 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
type IterationResult<T> = {
done: boolean;
value: Array<T | undefined>;
};
type Matcher<T> = (item: T | undefined) => boolean;
export interface nTupleConfig<T> {
export type TupleConfig<T> = {
list: T[];
maxItems?: number;
match?: Matcher<T>;
}
};
export declare class InvalidInvocationParameterError extends Error {
}
export declare const nTupleFromArray: <T>(config: nTupleConfig<T>) => {
[Symbol.iterator](): void;
export declare const tuplesFromArray: <T>(config: TupleConfig<T>) => {
[Symbol.iterator](): any;
next(): IterationResult<T>;
};
export {};
66 changes: 39 additions & 27 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,59 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nTupleFromArray = exports.InvalidInvocationParameterError = void 0;
exports.tuplesFromArray = exports.InvalidInvocationParameterError = void 0;
class InvalidInvocationParameterError extends Error {
}
exports.InvalidInvocationParameterError = InvalidInvocationParameterError;
;
const validateParamsOrThrow = (list, maxItems, match) => {
const validateParametersOrThrow = (list, maxItems, match) => {
if (!list || !Array.isArray(list)) {
const msg = `expected list to be an array but got ${list}`;
throw new InvalidInvocationParameterError(msg);
throw new InvalidInvocationParameterError('expected list to be an array');
}
if (typeof maxItems !== 'number'
|| (typeof maxItems === 'number' && maxItems <= 0)) {
const msg = `expected maxItems to be a positive integer (1 and above) but got ${maxItems}`;
throw new InvalidInvocationParameterError(msg);
const message = 'expected maxItems (when provided) to be a positive integer (1 and above)';
throw new InvalidInvocationParameterError(message);
}
if (typeof match !== 'function') {
const msg = `expected match to be a function but got ${match}`;
throw new InvalidInvocationParameterError(msg);
if (match !== undefined && typeof match !== 'function') {
const message = 'expected match (when provided) to be a function';
throw new InvalidInvocationParameterError(message);
}
};
const nTupleFromArray = (config) => {
const { list, maxItems = 2, match = (_) => true } = config;
validateParamsOrThrow(list, maxItems, match);
const tuplesFromArray = (config) => {
const { list, match, maxItems = 2 } = config;
validateParametersOrThrow(list, maxItems, match);
let cursor = 0;
const maxItemSize = Number.parseInt(`${maxItems}`, 10);
const iterable = {
[Symbol.iterator]() {
function next() {
if (cursor >= list.length)
return { done: true, value: [] };
const items = [];
const endIndex = cursor + maxItems;
while (cursor < endIndex) {
const item = list[cursor];
cursor += 1;
if (!match(item))
continue;
items.push(item);
return this;
},
next() {
if (cursor >= list.length) {
return { done: true, value: [] };
}
const items = [];
const endIndex = match === undefined
// A match funtion was provided. Okay to run to array end
// or until we've matched maxItemSize elements
? Math.min(cursor + maxItemSize, list.length)
// No match function was provided. We should run till we are
// out of items (list.length) or till we gotten the next set
// of maxItemSize items
: list.length;
while (cursor < endIndex) {
const item = list[cursor];
cursor += 1;
if (match && !match(item)) {
continue;
}
items.push(item);
if (match && items.length === maxItemSize) {
break;
}
return { done: false, value: items };
}
}
return { done: false, value: items };
},
};
return iterable;
};
exports.nTupleFromArray = nTupleFromArray;
exports.tuplesFromArray = tuplesFromArray;