Skip to content

Commit

Permalink
chore: format all files with prettier (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatiusmb authored Aug 1, 2023
1 parent d0446f2 commit 066d95b
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 203 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm-lock.yaml
232 changes: 116 additions & 116 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ Using modules provided by mauss, you can write shorter and simpler code with min
| [`web`](/src/web) | `'mauss/web'` |
| [`typings`](/src/typings) | `'mauss/typings'` |

***
---

<h3 align="center"><pre>Mauss | <a href="LICENSE">MIT License</a></pre></h3>
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
{
"name": "mauss",
"author": "Ignatius Bagus",
"description": "fast and efficient type-safe SDK",
"version": "0.6.0",
"description": "fast and efficient type-safe SDK",
"repository": "github:alchemauss/mauss",
"license": "MIT",
"author": "Ignatius Bagus",
"type": "module",
"types": "./core/index.d.ts",
"scripts": {
"clean": "git add * && git clean -dfx -e node_modules",
"watch": "pnpm pub:build --watch",
"format": "prettier -w . --plugin=prettier-plugin-sort-package-json",
"check": "pnpm check:code && pnpm check:style",
"check:code": "pnpm pub:build --noEmit",
"check:style": "prettier -c \"src/**/*.ts\"",
"check:style": "prettier -c . --plugin=prettier-plugin-sort-package-json",
"test": "pnpm test:unit",
"test:unit": "uvu -r tsm src \"(spec\\.ts)\"",
"pub:build": "tsc --project src",
"pub:format": "prettier -wu **/*.{d.ts,js}",
"prepublishOnly": "pnpm pub:build && pnpm pub:format"
},
"types": "./core/index.d.ts",
"exports": {
".": "./core/index.js",
"./api": "./api/index.js",
Expand All @@ -33,8 +35,6 @@
},
"packageManager": "[email protected]",
"prettier": "./prettier.json",
"repository": "github:alchemauss/mauss",
"bugs": "https://github.com/alchemauss/mauss/issues",
"keywords": [
"zero-dependency",
"strongly-typed",
Expand All @@ -53,6 +53,7 @@
"devDependencies": {
"@types/node": "^20.4.4",
"prettier": "^3.0.0",
"prettier-plugin-sort-package-json": "^0.1.0",
"tsm": "^2.3.0",
"typescript": "^5.1.6",
"uvu": "^0.5.6"
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

The `/api` module exports a `fetcher` factory that can be used to create a `send` function to make requests. The factory can be configured heavily to fit your needs, it accepts an object that can contain the following properties:

- `prepare` - a function that is called before the request is sent, it receives the specified `method` and `to` url string, and optionally a `body`, `from` URL, and `headers` object. It should *prepare* and return an object that satisfies the [`RequestInit`](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request) interface
- `intercept` - a function that is called against the `url` string before the request is sent
- `sweep` - a function that is called when `fetch` throws an error, it receives the thrown exception and returns a string
- `transform` - a function that is called when `fetch` returns a response, it receives the response and can return anything that will used as the `payload`, defaults to `r.json().catch(() => ({}))`
- `exit` - a function that is called after the response is transformed, it receives a clone of the initial response and the `payload`, and should return a string if the request was unsuccessful, or anything falsy such as `void | false | null | undefined` if it was successful
- `prepare` - a function that is called before the request is sent, it receives the specified `method` and `to` url string, and optionally a `body`, `from` URL, and `headers` object. It should _prepare_ and return an object that satisfies the [`RequestInit`](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request) interface
- `intercept` - a function that is called against the `url` string before the request is sent
- `sweep` - a function that is called when `fetch` throws an error, it receives the thrown exception and returns a string
- `transform` - a function that is called when `fetch` returns a response, it receives the response and can return anything that will used as the `payload`, defaults to `r.json().catch(() => ({}))`
- `exit` - a function that is called after the response is transformed, it receives a clone of the initial response and the `payload`, and should return a string if the request was unsuccessful, or anything falsy such as `void | false | null | undefined` if it was successful

```js
import { fetcher, type SendOptions } from 'mauss/api';
Expand Down
114 changes: 64 additions & 50 deletions src/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,32 @@ This namespace provides complete list of methods that covers all `typeof` values
compare.string('abc', 'def');
// and other primitives

[/* data */].sort(comparator);
[
/* data */
].sort(comparator);
```

### `compare.key`

```ts
type Wildcard = (x: any, y: any) => number;
export function key<
Identifier extends string
>(identifier: Identifier, comparator?: Wildcard): Wildcard;
export function key<Identifier extends string>(
identifier: Identifier,
comparator?: Wildcard,
): Wildcard;
```

A higher-order function that accepts a string as an identifier and an optional comparator function, it breaks up the identifier described by the dot (`.`) character and returns a curried function that accepts `(x, y)` with an object defined by the identifier.

```ts
const posts = [
{ date: { month: 4 } },
{ date: { month: 7 } },
{ date: { month: 6 } },
{ date: { month: 5 } },
{ date: { month: 1 } },
{ date: { month: 7 } },
{ date: { month: 2 } },
{ date: { month: 4 } },
{ date: { month: 7 } },
{ date: { month: 6 } },
{ date: { month: 5 } },
{ date: { month: 1 } },
{ date: { month: 7 } },
{ date: { month: 2 } },
];

posts.sort(compare.key('date.month'));
Expand All @@ -56,20 +59,31 @@ The optional comparator can be used when you have an existing custom sort functi

```ts
const posts = [
{ date: { month: 'March' } },
{ date: { month: 'June' } },
{ date: { month: 'May' } },
{ date: { month: 'April' } },
{ date: { month: 'January' } },
{ date: { month: 'June' } },
{ date: { month: 'February' } },
{ date: { month: 'March' } },
{ date: { month: 'June' } },
{ date: { month: 'May' } },
{ date: { month: 'April' } },
{ date: { month: 'January' } },
{ date: { month: 'June' } },
{ date: { month: 'February' } },
];

const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
const months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];

posts.sort(
compare.key('date.month', compare.order(months))
);
posts.sort(compare.key('date.month', compare.order(months)));
```

## `curry`
Expand Down Expand Up @@ -98,45 +112,45 @@ Simple `date/time` (`dt`) utility namespace.
type DateValue = string | number | Date;

interface BuildOptions {
base?: 'UTC';
base?: 'UTC';
}

interface TravelOptions {
/** relative point of reference to travel */
from?: DateValue;
/** relative days to travel in number */
to: number;
/** relative point of reference to travel */
from?: DateValue;
/** relative days to travel in number */
to: number;
}

export const dt: {
current(d?: DateValue): Date;
build(options: BuildOptions): (date?: DateValue) => (mask?: string) => string;
format: ReturnType<typeof this.build>;
travel({ from, to }: TravelOptions): Date;
}
current(d?: DateValue): Date;
build(options: BuildOptions): (date?: DateValue) => (mask?: string) => string;
format: ReturnType<typeof this.build>;
travel({ from, to }: TravelOptions): Date;
};
```

- `dt.current` is a function `(d?: DateValue) => Date` that optionally takes in a `DateValue` to be converted into a `Date` object, `new Date()` will be used if nothing is passed
- `dt.build` is a function that accepts `BuildOptions` and builds a formatter, a convenience export is included with all the default options as `dt.format`
- `dt.format` is a function that takes in a `DateValue` and returns a renderer that accepts a string mask to format the date in, defaults to `'DDDD, DD MMMM YYYY'`
- `dt.travel` is a function `({ from, to }) => Date` that takes in a `{ from, to }` object with `from` property being optional
- `dt.current` is a function `(d?: DateValue) => Date` that optionally takes in a `DateValue` to be converted into a `Date` object, `new Date()` will be used if nothing is passed
- `dt.build` is a function that accepts `BuildOptions` and builds a formatter, a convenience export is included with all the default options as `dt.format`
- `dt.format` is a function that takes in a `DateValue` and returns a renderer that accepts a string mask to format the date in, defaults to `'DDDD, DD MMMM YYYY'`
- `dt.travel` is a function `({ from, to }) => Date` that takes in a `{ from, to }` object with `from` property being optional

## `execute`

```ts
export function execute(
condition: truthy,
correct: () => AlsoPromise<void> | AnyFunction<[]>,
otherwise: () => AlsoPromise<void> | AnyFunction<[]> = () => {}
condition: truthy,
correct: () => AlsoPromise<void> | AnyFunction<[]>,
otherwise: () => AlsoPromise<void> | AnyFunction<[]> = () => {},
): void;
```

A convenience function to avoid writing [IIFE](https://developer.mozilla.org/en-US/docs/Glossary/IIFE)s. Instead of having `(...)()` everywhere in the codebase, it will be much nicer to see

```ts
execute(you === world, () => {
// ...
})
// ...
});
```

Combined with Svelte's `$:`, which is a way to mark statements as reactive, we can have `async` operations that reacts to changes in the application and `await` them as well.
Expand Down Expand Up @@ -174,15 +188,15 @@ export function identical(x: unknown, y: unknown): boolean;

A function to check for values equality between two variables. This will work for any data type except `function`, which will always return true when two function are being compared. The heuristics are as follows:

- fails immediately when the type of `x` and `y` are not the same
- type of `function` are not comparable, always returns true
- type of `symbol` is converted and compared as a `string`
- primitive values are compared using strict equality operator
- type of `object`, two empty array or object are considered the same
- type of `object`, comparing array also considers its length and item order
- type of `object`, two object must have the same keys before comparing its values
- type of `object`, the order of key-value pair does not matter for equality check
- `identical` is infinitely recursive for any amount of nested array/object
- fails immediately when the type of `x` and `y` are not the same
- type of `function` are not comparable, always returns true
- type of `symbol` is converted and compared as a `string`
- primitive values are compared using strict equality operator
- type of `object`, two empty array or object are considered the same
- type of `object`, comparing array also considers its length and item order
- type of `object`, two object must have the same keys before comparing its values
- type of `object`, the order of key-value pair does not matter for equality check
- `identical` is infinitely recursive for any amount of nested array/object

## `inverse`

Expand Down
14 changes: 7 additions & 7 deletions src/guards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import { bulwark } from 'mauss/guards';

let key = 'a' as 'a' | 'z';
switch (key) {
case 'a':
return key.charCodeAt();
default:
// Argument of type 'string' is not assignable to parameter of type 'never'.
return bulwark(key);
case 'a':
return key.charCodeAt();
default:
// Argument of type 'string' is not assignable to parameter of type 'never'.
return bulwark(key);
}
```

Expand Down Expand Up @@ -47,8 +47,8 @@ A number guard that returns `true` if the input exists or is a number greater th

A utility guard that takes in any guards above and negates the result. For example,

- `not(exists)` will return `true` if the input is nullish or an empty string
- `not(natural)` will return `true` if the input exists or is a number less than or equal to 0.
- `not(exists)` will return `true` if the input is nullish or an empty string
- `not(natural)` will return `true` if the input exists or is a number less than or equal to 0.

## `lowercase`

Expand Down
14 changes: 7 additions & 7 deletions src/std/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ Original function, iterate over the key-value pair of an object, returns a new o

```typescript
export function iterate<T extends object>(
object: T,
callback: AnyFunction<
[entry: Entries<T>[number], index: number],
void | Falsy | [IndexSignature, any]
> = ([k, v]) => [k, clone(v)]
object: T,
callback: AnyFunction<
[entry: Entries<T>[number], index: number],
void | Falsy | [IndexSignature, any]
> = ([k, v]) => [k, clone(v)],
): T;
```

Expand Down Expand Up @@ -93,9 +93,9 @@ This assumes the braces inside the template string are balanced and not nested.

```typescript
export function tsf(
template: string
template: string,
): (table: {
[key: string]: string | false | Nullish | ((key: string) => string | false | Nullish);
[key: string]: string | false | Nullish | ((key: string) => string | false | Nullish);
}) => string;
```

Expand Down
22 changes: 11 additions & 11 deletions src/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ This namespace extends the [`Navigator` object](https://developer.mozilla.org/en

```ts
export function copy(
data: string | ClipboardItem,
handler: {
accept?(): void | Promise<void>;
reject?(): void | Promise<void>;
} = {}
data: string | ClipboardItem,
handler: {
accept?(): void | Promise<void>;
reject?(): void | Promise<void>;
} = {},
): void;

export function item(
type: string,
data: string | Blob,
options?: ClipboardItemOptions
type: string,
data: string | Blob,
options?: ClipboardItemOptions,
): ClipboardItem;

export function paste(type: 'blob'): Promise<ClipboardItems>;
Expand All @@ -39,9 +39,9 @@ Query string encoder (`qse`) encodes key-value pairs from an object into a query
```ts
type BoundValues = Nullish | Primitives;
export function qse<T extends object>(
bound: T[keyof T] extends BoundValues | readonly BoundValues[] ? T : never,
transformer = (final: string) => `?${final}`
): string
bound: T[keyof T] extends BoundValues | readonly BoundValues[] ? T : never,
transformer = (final: string) => `?${final}`,
): string;
```

The first parameter `bound` only accepts an object with nullish and primitive literals or an array of those values.
Expand Down

0 comments on commit 066d95b

Please sign in to comment.