Skip to content

Commit

Permalink
minor improvements in cookies and DOM shim
Browse files Browse the repository at this point in the history
  • Loading branch information
mitranim committed Jun 24, 2024
1 parent 50887c8 commit a8b0507
Show file tree
Hide file tree
Showing 24 changed files with 116 additions and 107 deletions.
6 changes: 3 additions & 3 deletions docs/cli_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
CLI args:

```js
import * as cl from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/cli.mjs'
import * as cl from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/cli.mjs'

const cli = cl.Flag.os()

Expand All @@ -34,15 +34,15 @@ console.log(...cli.args)
Console clearing:

```js
import * as cl from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/cli.mjs'
import * as cl from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/cli.mjs'

cl.emptty()
```

Clearing the console only once, before running your code:

```js
import 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/cli_emptty.mjs'
import 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/cli_emptty.mjs'
```

## API
Expand Down
8 changes: 4 additions & 4 deletions docs/coll_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Port and rework of https://github.com/mitranim/jol.
## Usage

```js
import * as c from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/coll.mjs'
import * as c from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/coll.mjs'
```

## API
Expand Down Expand Up @@ -101,8 +101,8 @@ Links: [source](../coll.mjs#L101); [test/example](../test/coll_test.mjs#L218).
Variant of [#`Bmap`](#class-bmap) with support for key and value checks. Subclasses must override methods `.reqKey` and `.reqVal`. These methods are automatically called by `.set`. Method `.reqKey` must validate and return the given key, and method `.reqVal` must validate and return the given value. Use type assertions provided by [`lang`](lang_readme.md).

```js
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as c from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/coll.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'
import * as c from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/coll.mjs'

class StrNatMap extends c.TypedMap {
reqKey(key) {return l.reqStr(key)}
Expand Down Expand Up @@ -242,7 +242,7 @@ Differences and advantages over `Array`:
The overhead of the wrapper is insignificant.

```js
import * as c from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/coll.mjs'
import * as c from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/coll.mjs'

console.log(new c.Vec())
// Vec{$: []}
Expand Down
2 changes: 1 addition & 1 deletion docs/dom_glob_native_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
## Usage

```js
import * as dg from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/dom_glob_native.mjs'
import * as dg from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/dom_glob_native.mjs'

console.log(dg.glob)
```
Expand Down
2 changes: 1 addition & 1 deletion docs/dom_glob_shim_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
## Usage

```js
import * as dg from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/dom_glob_shim.mjs'
import * as dg from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/dom_glob_shim.mjs'

console.log(dg.glob)
```
Expand Down
2 changes: 1 addition & 1 deletion docs/dom_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
## Usage

```js
import * as d from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/dom.mjs'
import * as d from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/dom.mjs'
```

## API
Expand Down
24 changes: 12 additions & 12 deletions docs/dom_reg_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
Example mockup for a pushstate link.

```js
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/dom_reg.mjs'
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/dom_reg.mjs'

// Immediately ready for use. Tag is automatically set to `a-btn`.
class Btn extends dr.HTMLButtonElement {
Expand Down Expand Up @@ -61,20 +61,20 @@ document.body.append(new MyLink(`click me`, `/some-link`))

### `function reg`

Links: [source](../dom_reg.mjs#L172); [test/example](../test/dom_reg_test.mjs#L18).
Links: [source](../dom_reg.mjs#L177); [test/example](../test/dom_reg_test.mjs#L18).

Shortcut for calling `Reg.main.reg`. Takes a custom element class and idempotently registers it, automatically deriving the custom element tag name _and_ the base tag for `extends`.

### `class Reg`

Links: [source](../dom_reg.mjs#L174); [test/example](../test/dom_reg_test.mjs#L45).
Links: [source](../dom_reg.mjs#L179); [test/example](../test/dom_reg_test.mjs#L45).

Registry for custom DOM element classes. Automatically derives tag name from class name, using salting when necessary to avoid collisions. Supports idempotent registration which can be safely called in an element constructor. Allows immediate registration, deferred registration, or a mix of those.

By default, this registry has **no global side effects**. To enable global registration, provide a "definer" to the registry.

```js
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/dom_reg.mjs'
import * as dr from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/dom_reg.mjs'

class Btn extends HTMLButtonElement {
static customName = `some-btn`
Expand All @@ -95,11 +95,11 @@ dr.Reg.main.setDefiner(customElements)
The following APIs are exported but undocumented. Check [dom_reg.mjs](../dom_reg.mjs).

* [`class TagToCls`](../dom_reg.mjs#L13)
* [`class ClsToTag`](../dom_reg.mjs#L98)
* [`class CustomElementRegistry`](../dom_reg.mjs#L134)
* [`function MixReg`](../dom_reg.mjs#L159)
* [`class MixRegCache`](../dom_reg.mjs#L161)
* [`function isDefiner`](../dom_reg.mjs#L280)
* [`function optDefiner`](../dom_reg.mjs#L281)
* [`function isCustomName`](../dom_reg.mjs#L284)
* [`function reqCustomName`](../dom_reg.mjs#L288)
* [`class ClsToTag`](../dom_reg.mjs#L103)
* [`class CustomElementRegistry`](../dom_reg.mjs#L139)
* [`function MixReg`](../dom_reg.mjs#L164)
* [`class MixRegCache`](../dom_reg.mjs#L166)
* [`function isDefiner`](../dom_reg.mjs#L285)
* [`function optDefiner`](../dom_reg.mjs#L286)
* [`function isCustomName`](../dom_reg.mjs#L289)
* [`function reqCustomName`](../dom_reg.mjs#L293)
2 changes: 1 addition & 1 deletion docs/dom_shim_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
## Usage

```js
import * as ds from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/dom_shim.mjs'
import * as ds from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/dom_shim.mjs'
```

## API
Expand Down
14 changes: 7 additions & 7 deletions docs/http_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ HTTP request/response utils are ported and reworked from https://github.com/mitr
## Usage

```js
import * as h from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/http.mjs'
import * as h from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/http.mjs'

const reqBody = {msg: `hello world`}
const resBody = await h.reqBui().to(`/api`).post().json(reqBody).fetchOkJson()
Expand Down Expand Up @@ -234,8 +234,8 @@ rou.groups // {key: `path`}
Routing is imperative:

```js
import * as h from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/http.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as h from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/http.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'

const nextPage = route(window.location)

Expand Down Expand Up @@ -263,7 +263,7 @@ Short for "request router" or "request-response router". Advanced version of [#`
Routing can be shared between SSR and SPA:

```js
import * as h from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/http.mjs'
import * as h from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/http.mjs'

function route(rou) {
l.reqInst(rou, h.ReqRou)
Expand Down Expand Up @@ -365,9 +365,9 @@ The following APIs are exported but undocumented. Check [http.mjs](../http.mjs).
* [`function cook`](../http.mjs#L496)
* [`class Cookie`](../http.mjs#L498)
* [`class Cookies`](../http.mjs#L607)
* [`function reqBody`](../http.mjs#L641)
* [`function optBody`](../http.mjs#L642)
* [`const bodyFuns`](../http.mjs#L643)
* [`function reqBody`](../http.mjs#L644)
* [`function optBody`](../http.mjs#L645)
* [`const bodyFuns`](../http.mjs#L646)


## Misc
Expand Down
20 changes: 10 additions & 10 deletions docs/iter_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Port and rework of https://github.com/mitranim/fpx.
## Usage

```js
import * as i from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/iter.mjs'
import * as i from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/iter.mjs'
```

## Perf
Expand Down Expand Up @@ -314,8 +314,8 @@ Signature: `(Iter<A>, {new(A): B}) => B[]`.
Similar to [#`map`](#function-map), but instead of taking an arbitrary function, takes a class and calls it with `new` for each element.

```js
import * as i from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/iter.mjs'
import * as o from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/obj.mjs'
import * as i from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/iter.mjs'
import * as o from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/obj.mjs'

class Model extends o.Dict {pk() {return this.id}}
class Person extends Model {}
Expand Down Expand Up @@ -603,7 +603,7 @@ Links: [source](../iter.mjs#L396); [test/example](../test/iter_test.mjs#L1116).
Syntactic shortcut for creating a `Set` via variadic call.

```js
import * as i from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/iter.mjs'
import * as i from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/iter.mjs'

i.setOf(10, 20, 30)
// Set{10, 20, 30}
Expand Down Expand Up @@ -676,8 +676,8 @@ Similar to [#`map`](#function-map) but for dicts.
* The mapping function receives only one argument: each value.

```js
import * as i from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/iter.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as i from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/iter.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'

i.mapDict({one: 10, two: 20}, l.inc)
// {one: 11, two: 21}
Expand All @@ -698,8 +698,8 @@ Similar to [#`filter`](#function-filter) but for dicts.
* The mapping function receives each value.

```js
import * as i from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/iter.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as i from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/iter.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'

i.pick({one: -20, two: -10, three: 10, four: 20}, l.isFinPos)
// {three: 10, four: 20}
Expand All @@ -720,8 +720,8 @@ Similar to [#`reject`](#function-reject) but for dicts.
* The mapping function receives each value.

```js
import * as i from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/iter.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as i from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/iter.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'

i.omit({one: -20, two: -10, three: 10, four: 20}, l.isFinPos)
// {one: -20, two: -10}
Expand Down
24 changes: 12 additions & 12 deletions docs/lang_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Port and rework of https://github.com/mitranim/fpx.
## Usage

```js
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'
```

## API
Expand All @@ -121,7 +121,7 @@ Links: [source](../lang.mjs#L3); [test/example](../test/lang_test.mjs#L219).
True for `null` and `undefined`. Same as `value == null`. Incidentally, these are the only values that produce an exception when attempting to read a property: `null.someProperty`.

```js
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'

// Definition
function isNil(value) {return value == null}
Expand Down Expand Up @@ -155,7 +155,7 @@ Links: [source](../lang.mjs#L19); [test/example](../test/lang_test.mjs#L244).
Same as `typeof val === 'number'`. True if the value is a primitive number, _including_ `NaN` and `±Infinity`. In most cases you should use [#`isFin`](#function-isfin) instead.

```js
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'

l.isNum(1)
// true
Expand All @@ -174,7 +174,7 @@ Links: [source](../lang.mjs#L25); [test/example](../test/lang_test.mjs#L256).
Same as ES2015's [`Number.isFinite`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite). True if `val` is a primitive number and is _not_ `NaN` or `±Infinity`. In most cases you should prefer `isFin` over `isNum`.

```js
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'

l.isFin(1)
// true
Expand Down Expand Up @@ -502,7 +502,7 @@ Signature: `(val, test) => val` where `test: val => bool`.
Short for "require". Minification-friendly assertion. If `!test(val)`, throws an informative `TypeError`. Otherwise, returns `val` as-is.

```js
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'

l.req({one: `two`}, l.isObj)
// {one: `two`}
Expand Down Expand Up @@ -601,7 +601,7 @@ Identity test: same as `===`, but considers `NaN` equal to `NaN`. Equivalent to
Note that [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) implements [_SameValue_](https://www.ecma-international.org/ecma-262/6.0/#sec-samevalue), which treats `-0` and `+0` as _distinct values_. This is typically undesirable. As a result, you should prefer `l.is` over `===` or `Object.is`.

```js
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'

l.is(1, '1')
// false
Expand Down Expand Up @@ -641,7 +641,7 @@ Links: [source](../lang.mjs#L424); [test/example](../test/lang_test.mjs#L1723).
Takes a value and creates a function that always returns that value. Sometimes useful with higher order functions.

```js
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'

const constant = l.val(1)

Expand All @@ -659,7 +659,7 @@ Links: [source](../lang.mjs#L425); [test/example](../test/lang_test.mjs#L1737).
Same as `throw` but an expression rather than a statement. Also sometimes useful with higher-order functions.

```js
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'

const x = someTest ? someValue : l.panic(Error(`unreachable`))
```
Expand All @@ -679,7 +679,7 @@ Like [`Function.prototype.bind`](https://developer.mozilla.org/en-US/docs/Web/Ja
Returns a new function that represents [partial application](https://en.wikipedia.org/wiki/Partial_application) of the given function, a common tool in functional programming. When called, it joins arguments from both calls and invokes the original function. Think of it like splitting a function call in two, or more. Performance is inferior to closures; avoid in hotspots.

```js
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'

const inc = l.bind(l.add, 1)

Expand All @@ -696,7 +696,7 @@ Links: [source](../lang.mjs#L431); [test/example](../test/lang_test.mjs#L1700).
Returns a new function that negates the result of the given function, like a delayed `!`.

```js
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'

function eq(a, b) {return a === b}

Expand All @@ -716,7 +716,7 @@ Links: [source](../lang.mjs#L436); [test/example](../test/lang_test.mjs#L1117).
Same as the `in` operator, but returns `false` for [#primitives](#function-isprim) instead of throwing an exception:

```js
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'

l.hasIn(new Number(10), `toString`)
// true
Expand Down Expand Up @@ -747,7 +747,7 @@ Links: [source](../lang.mjs#L439); [test/example](../test/lang_test.mjs#L1159).
Returns `true` if the target is [#non-primitive](#function-iscomp) and has the given property on its prototype. As a consequence, this returns `false` if the target is a primitive, or has the given property as an "own" property, either enumerable or not.

```js
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'

l.hasInherited([10, 20, 30], `length`)
// false
Expand Down
12 changes: 6 additions & 6 deletions docs/obj_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
## Usage

```js
import * as o from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/obj.mjs'
import * as o from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/obj.mjs'
```

## API
Expand Down Expand Up @@ -82,8 +82,8 @@ Performance characteristics:
* When the number of declared properties is significantly smaller than the number of provided properties, this tends to be faster than the aforementioned assignment functions.

```js
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as o from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/obj.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'
import * as o from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/obj.mjs'

class Person extends o.Struct {
static Spec = class extends super.Spec {
Expand Down Expand Up @@ -126,8 +126,8 @@ Differences from [#`Struct`](#class-struct):
* Measurably worse performance.

```js
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/lang.mjs'
import * as o from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/obj.mjs'
import * as l from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/lang.mjs'
import * as o from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/obj.mjs'

class Person extends o.StructLax {
static Spec = class extends super.Spec {
Expand Down Expand Up @@ -160,7 +160,7 @@ Links: [source](../obj.mjs#L304); [test/example](../test/obj_test.mjs#L786).
Takes a class and hacks its prototype, converting all non-inherited getters to lazy/memoizing versions of themselves that only execute _once_. The resulting value replaces the getter. Inherited getters are unaffected.

```js
import * as o from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].53/obj.mjs'
import * as o from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected].54/obj.mjs'

class Bucket {
static {o.memGet(this)}
Expand Down
Loading

0 comments on commit a8b0507

Please sign in to comment.