1
0
mirror of https://github.com/robonen/tools.git synced 2026-03-20 10:54:44 +00:00

refactor(packages/stdlib): update dir names and imports

This commit is contained in:
2024-10-24 07:29:37 +07:00
parent 85eb28a5dc
commit 29d8aa086c
6 changed files with 43 additions and 36 deletions

View File

@@ -1 +1,5 @@
export * from './getByPath'; export * from './cluster';
export * from './first';
export * from './last';
export * from './sum';
export * from './unique';

View File

@@ -0,0 +1 @@
export * from './getByPath';

View File

@@ -1,3 +1,6 @@
import { last } from '../../arrays';
import { isArray } from '../../types';
export type StackOptions = { export type StackOptions = {
maxSize?: number; maxSize?: number;
}; };
@@ -37,7 +40,7 @@ export class Stack<T> implements Iterable<T>, AsyncIterable<T> {
*/ */
constructor(initialValues?: T[] | T, options?: StackOptions) { constructor(initialValues?: T[] | T, options?: StackOptions) {
this.maxSize = options?.maxSize ?? Infinity; this.maxSize = options?.maxSize ?? Infinity;
this.stack = Array.isArray(initialValues) ? initialValues : initialValues ? [initialValues] : []; this.stack = isArray(initialValues) ? initialValues : initialValues ? [initialValues] : [];
} }
/** /**
@@ -95,7 +98,7 @@ export class Stack<T> implements Iterable<T>, AsyncIterable<T> {
if (this.isEmpty) if (this.isEmpty)
throw new RangeError('Stack is empty'); throw new RangeError('Stack is empty');
return this.stack[this.stack.length - 1]; return last(this.stack);
} }
/** /**

View File

@@ -1,36 +1,36 @@
import { describe, expect, it } from 'vitest'; import { describe, expect, it } from 'vitest';
import { templateObject } from '.'; import { templateObject } from '.';
describe('templateObject', () => { describe.todo('templateObject', () => {
// it('replace template placeholders with corresponding values from args', () => { it('replace template placeholders with corresponding values from args', () => {
// const template = 'Hello, {names.0}!'; const template = 'Hello, {names.0}!';
// const args = { names: ['John'] }; const args = { names: ['John'] };
// const result = templateObject(template, args); const result = templateObject(template, args);
// expect(result).toBe('Hello, John!'); expect(result).toBe('Hello, John!');
// }); });
// it('replace template placeholders with corresponding values from args', () => { it('replace template placeholders with corresponding values from args', () => {
// const template = 'Hello, {name}!'; const template = 'Hello, {name}!';
// const args = { name: 'John' }; const args = { name: 'John' };
// const result = templateObject(template, args); const result = templateObject(template, args);
// expect(result).toBe('Hello, John!'); expect(result).toBe('Hello, John!');
// }); });
// it('replace template placeholders with fallback value if corresponding value is undefined', () => { it('replace template placeholders with fallback value if corresponding value is undefined', () => {
// const template = 'Hello, {name}!'; const template = 'Hello, {name}!';
// const args = { age: 25 }; const args = { age: 25 };
// const fallback = 'Guest'; const fallback = 'Guest';
// const result = templateObject(template, args, fallback); const result = templateObject(template, args, fallback);
// expect(result).toBe('Hello, Guest!'); expect(result).toBe('Hello, Guest!');
// }); });
// it(' replace template placeholders with fallback value returned by fallback function if corresponding value is undefined', () => { it(' replace template placeholders with fallback value returned by fallback function if corresponding value is undefined', () => {
// const template = 'Hello, {name}!'; const template = 'Hello, {name}!';
// const args = { age: 25 }; const args = { age: 25 };
// const fallback = (key: string) => `Unknown ${key}`; const fallback = (key: string) => `Unknown ${key}`;
// const result = templateObject(template, args, fallback); const result = templateObject(template, args, fallback);
// expect(result).toBe('Hello, Unknown name!'); expect(result).toBe('Hello, Unknown name!');
// }); });
it('replace template placeholders with nested values from args', () => { it('replace template placeholders with nested values from args', () => {
const result = templateObject('Hello {{user.name}, your address {user.addresses.0.street}', { const result = templateObject('Hello {{user.name}, your address {user.addresses.0.street}', {

View File

@@ -1,4 +1,4 @@
import { getByPath, type Generate } from '../../arrays'; import { getByPath, type Generate } from '../../collections';
import { isFunction } from '../../types'; import { isFunction } from '../../types';
/** /**
@@ -57,10 +57,9 @@ export function templateObject<T extends string, A extends Generate<ExtractPlace
// templateObject('Hello {user.name}, your address {user.addresses.0.street}', { // templateObject('Hello {user.name}, your address {user.addresses.0.street}', {
// user: { // user: {
// name: 'John Doe', // name: 'John',
// addresses: [ // addresses: [
// { street: '123 Main St', city: 'Springfield'}, // { city: 'New York', street: '5th Avenue' },
// { street: '456 Elm St', city: 'Shelbyville'},
// ], // ],
// }, // },
// }); // });