Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ahrjarrett/any-ts
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.45.0
Choose a base ref
...
head repository: ahrjarrett/any-ts
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Loading
7 changes: 6 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
@@ -2,7 +2,12 @@
"$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json",
"access": "public",
"baseBranch": "main",
"changelog": "@changesets/cli/changelog",
"changelog": [
"@changesets/changelog-github",
{
"repo": "ahrjarrett/any-ts"
}
],
"commit": false,
"fixed": [],
"ignore": [],
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @ahrjarrett
191 changes: 191 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,196 @@
# any-ts

## 0.48.1

### Patch Changes

- [#171](https://github.com/ahrjarrett/any-ts/pull/171) [`47039da`](https://github.com/ahrjarrett/any-ts/commit/47039dae4b17697361cb3678d087c2a407355ec3) Thanks [@ahrjarrett](https://github.com/ahrjarrett)! - feat: adds `inline` type utility

### new features

- new [inline](https://github.com/ahrjarrett/any-ts/compare/%40ahrjarrett/v0.48.1?expand=1#diff-8f609800e1fe1486238044764d22867704573f7319ac89246dfcedfe9b3d7b68R9) utility

`inline` is basically a type-level identity function.

like its runtime counterpart, it can be pretty useful.

the name `inline` refers to the particular use case that I personally usually use it for,
which is for wrapping a type literal so that an interface can extend it.

```typescript
import type { inline } from "any-ts";

//////////////
/// example

/**
* did you know you can make an interface out of an array?
* this can be useful when you want to preserve the
* identifier: vvvv */
interface Numbers extends inline<number[]> {}

declare const numbers: Numbers;
// ^? const numbers: Numbers

// normal array behavior is preserved:
const copy = [...ex_01.numbers];
// ^? const copy: number[]
```

## 0.48.0

### Minor Changes

- [#169](https://github.com/ahrjarrett/any-ts/pull/169) [`648a8de`](https://github.com/ahrjarrett/any-ts/commit/648a8de2307062e8ebd78967433d3fbde64f9669) Thanks [@ahrjarrett](https://github.com/ahrjarrett)! - ### breaking changes
- All of the members of Universal namespace have changed their implementations
- Since `any-ts` is still pre v1.0, this is a minor version bump.
- The API is relatively stable; I expect one (1) more breaking change before releasing v1.0.0 this fall

## 0.47.4

### Patch Changes

- [#167](https://github.com/ahrjarrett/any-ts/pull/167) [`4234c81`](https://github.com/ahrjarrett/any-ts/commit/4234c8192815d8415b2722aa56285d44f942d4c2) Thanks [@ahrjarrett](https://github.com/ahrjarrett)! - deprecate: `Identity` -- use `newtype` instead

## 0.47.3

### Patch Changes

- [#165](https://github.com/ahrjarrett/any-ts/pull/165) [`60f77df`](https://github.com/ahrjarrett/any-ts/commit/60f77df8c7b48ca5535f408be5ddcc6bb0dabb44) Thanks [@ahrjarrett](https://github.com/ahrjarrett)! - fix: `some.entriesOf` when used in matching position

## 0.47.2

### Patch Changes

- [#163](https://github.com/ahrjarrett/any-ts/pull/163) [`29e5043`](https://github.com/ahrjarrett/any-ts/commit/29e5043efcb49ca025693ba97527a27ed964af3e) Thanks [@ahrjarrett](https://github.com/ahrjarrett)! - feat: adds `some.entriesOf`

## 0.47.1

### Patch Changes

- [#161](https://github.com/ahrjarrett/any-ts/pull/161) [`b06a828`](https://github.com/ahrjarrett/any-ts/commit/b06a8286141de26b7729f5fae6b383e2e9d54178) Thanks [@ahrjarrett](https://github.com/ahrjarrett)! - fix: correctly exports `match.finite` namespace

## 0.47.0

### Minor Changes

- [#157](https://github.com/ahrjarrett/any-ts/pull/157) [`9fb7871`](https://github.com/ahrjarrett/any-ts/commit/9fb787131d523b176913da5cf7f3c91d952ce317) Thanks [@ahrjarrett](https://github.com/ahrjarrett)! - break: renames `match.finite*` to `match.finite.*`

for example:

```
match.finiteArray -> match.finite.array
match.nonfiniteArray -> match.nonfinite.array
```

### Patch Changes

- [#160](https://github.com/ahrjarrett/any-ts/pull/160) [`350fd9f`](https://github.com/ahrjarrett/any-ts/commit/350fd9f26f853de331be1c88ae51cccadc2adbe8) Thanks [@ahrjarrett](https://github.com/ahrjarrett)! - fix: re-exports `some.instanceOf`; feat: adds `any.maybeIndexedBy`

## 0.46.0

### Minor Changes

- bf5df0f: ### new features

- added `match`, a namespace for advanced pattern matching
- added `any.functions` to describe any array of functions

### breaking changes

a few members of the `some` namespace behave differently than before:

- `some.keyOf`: this change was made to support a homomorphic `object.map` function
that operates on both arrays and objects, preserves structure in either case.

An example implementation:

```typescript
/**
* {@link map `map [overload 1/2]`} ("data-last")
*
* [TypeScript playground](https://tsplay.dev/weA2Yw)
*
* {@link map `map`} takes two arguments:
* 1. a function
* 2. a composite data structure that contains one or more targets to apply the function to
*
* A unique feature of this implementation is its polymorphism: it doesn't care whether the
* composite data structure is an array, or whether it's an object. It will apply the argument
* to each of the children, and will preserve the structure of the original shape.
*
* **Trade-off:** the data-last overload of {@link map `map`} is optimized for function composition.
* It works best when used inside a call to {@link fn.pipe `fn.pipe`} or {@link fn.flow `fn.flow`}.
* It comes with greater potential for code re-use, at the cost of slightly slower performance.
*
* **Ergonomics:** if you'd prefer to provide both arguments at the same time, see overload #2.
*/
export function map<const xs, target>(
fn: (x: xs[some.keyof<xs>], ix: some.keyof<xs>, xs: xs) => target
): (xs: xs) => { [ix in keyof xs]: target };
/**
* {@link map `map [overload 2/2]`} ("data-first")
*
* [TypeScript playground](https://tsplay.dev/weA2Yw)
*
* {@link map `map`} is a polymorphic function that accepts a function and a data structure (such
* as an array or object) to apply the function to.
*
* A unique feature of this implementation is its ability to abstract away the type of the data
* structure it maps the function over; whether you pass it an object or an array, it will handle
* applying the function to the data strucuture's values and returning a data structure whose type
* corresponds 1-1 with the type of input.
*
* **Trade-off:** the data-first overload of {@link map `map`} evaluates eagerly. It comes with
* slightly better performance than the data-last overload, at the cost of reusability.
*
* **Ergonomics:** if you'd prefer to use {@link map `map`} in a pipeline, see overload #1.
*/
export function map<const xs, target>(
xs: xs,
fn: (x: xs[some.keyof<xs>], xs: xs) => target
): { [ix in keyof xs]: target };
// impl.
export function map<const xs, target>(
...args:
| [fn: (x: xs[some.keyof<xs>], ix: some.keyof<xs>, xs: xs) => target]
| [
xs: xs,
fn: (x: xs[some.keyof<xs>], ix: some.keyof<xs>, xs: xs) => target
]
) {
if (args.length === 1) return (xs: xs) => map(xs, args[0]);
else {
const [xs, fn] = args;
if (globalThis.Array.isArray(xs)) return xs.map(fn as never);
else {
let out: any.struct = {};
for (const k in xs) out[k] = fn(xs[k] as never, k as never, xs);
return out;
}
}
}
```

- `some.entryOf`
slightly different semantics to support a polymorphic `object.entries` function

- `some.valueOf`
slightly different semantics to support a polymorphic `object.values` function

## 0.45.2

### Patch Changes

- 1ea3201: fix: `Case.pascal` and `Case.camel` converting all caps incorrectly
- 58593b0: fix: removes "module" field in manifest so `any-ts` plays nice with Vite

## 0.45.1

### Patch Changes

- d10ee8c: fix: ensure `string.intercalate` produces a string result

## 0.45.0

### Minor Changes
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "any-ts",
"private": false,
"version": "0.45.0",
"version": "0.48.1",
"type": "module",
"author": {
"name": "Andrew Jarrett",
@@ -17,7 +17,6 @@
"license": "MIT",
"types": "dist/index.d.ts",
"main": "dist/index.js",
"module": "dist/index.mjs",
"files": [
"dist/index.d.ts"
],
@@ -36,6 +35,7 @@
},
"devDependencies": {
"@arktype/attest": "^0.7.3",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@types/node": "^20.12.7",
"init": "^0.1.2",
Loading