Skip to content

Commit

Permalink
Merge branch 'master' into auto-pull
Browse files Browse the repository at this point in the history
  • Loading branch information
nin-jin authored Jan 14, 2024
2 parents 065c5ef + 8983bad commit 793f0bf
Show file tree
Hide file tree
Showing 92 changed files with 699 additions and 469 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/mam.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: mam

on:
workflow_dispatch:
push:
branches:
- master
paths:
- '.github/workflows/mam.yml'
- 'build/**'
pull_request:
schedule:
- cron: "0 7 * * *"

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: hyoo-ru/mam_build@master2
with:
package: mol
modules: build
- uses: JS-DevTools/npm-publish@v1
if: ${{ github.ref == 'refs/heads/master' }}
with:
token: ${{ secrets.NPM_AUTH_TOKEN }}
package: ./mol/build/-/package.json
1 change: 1 addition & 0 deletions app/docs/demo.meta.tree
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ include \/mol/list/demo
include \/mol/list/demo/table
include \/mol/list/demo/tree
include \/mol/map/yandex/demo
include \/mol/mutable/demo
include \/hyoo/marked/demo
include \/hyoo/harp/demo
- include \/mol/message/demo
Expand Down
4 changes: 2 additions & 2 deletions assert/assert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ namespace $ {
} ,

'two must be unique'() {
$mol_assert_unique( [ 3 ] , [ 3 ] )
$mol_assert_unique( [ 2 ] , [ 3 ] )
} ,

'three must be unique'() {
$mol_assert_unique( [ 3 ] , [ 3 ] , [ 3 ] )
$mol_assert_unique( [ 1 ] , [ 2 ] , [ 3 ] )
} ,

'two must be alike'() {
Expand Down
102 changes: 43 additions & 59 deletions assert/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ namespace $ {

/**
* Argument must be Truthy
* @example
* $mol_assert_ok( 1 ) // Passes
* $mol_assert_ok( 0 ) // Fails because Falsy
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
* @deprecated use $mol_assert_equal instead
*/
export function $mol_assert_ok( value : any ) {
if( value ) return
Expand All @@ -14,10 +11,7 @@ namespace $ {

/**
* Argument must be Falsy
* @example
* $mol_assert_ok( 0 ) // Passes
* $mol_assert_ok( 1 ) // Fails because Truthy
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
* @deprecated use $mol_assert_equal instead
*/
export function $mol_assert_not( value : any ) {
if( !value ) return
Expand All @@ -32,7 +26,10 @@ namespace $ {
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , Error ) // Passes because throws right class
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
*/
export function $mol_assert_fail( handler : ()=> any , ErrorRight? : any ) {
export function $mol_assert_fail(
handler: ()=> any ,
ErrorRight: string | typeof Error | typeof Promise
) {

const fail = $.$mol_fail

Expand All @@ -43,14 +40,12 @@ namespace $ {

} catch( error: any ) {

if( !ErrorRight ) return error

$.$mol_fail = fail

if( typeof ErrorRight === 'string' ) {
$mol_assert_equal( error.message, ErrorRight )
} else {
$mol_assert_ok( error instanceof ErrorRight )
$mol_assert_equal( error instanceof ErrorRight, true )
}

return error
Expand All @@ -62,77 +57,66 @@ namespace $ {
$mol_fail( new Error( 'Not failed' ) )
}

/**
* All arguments must be equal.
* @example
* $mol_assert_equal( 1 , 1 , 1 ) // Passes
* $mol_assert_equal( 1 , 1 , 2 ) // Fails because 1 !== 2
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
*/
export function $mol_assert_equal< Value >( ... args : [ Value, Value, ...Value[] ] ) {
for( let i = 0 ; i < args.length ; ++i ) {
for( let j = 0 ; j < args.length ; ++j ) {
if( i === j ) continue
if( Number.isNaN( args[i] as any as number ) && Number.isNaN( args[j] as any as number ) ) continue
if( args[i] !== args[j] ) $mol_fail( new Error( `Not equal (${i+1}:${j+1})\n${ args[i] }\n${ args[j] }` ) )
}
}
/** @deprecated Use $mol_assert_equal */
export function $mol_assert_like< Value >( ... args : [ Value, Value, ...Value[] ] ) {
$mol_assert_equal( ... args )
}

/**
* All arguments must be not equal to each other.
* All arguments must not be structural equal to each other.
* @example
* $mol_assert_unique( 1 , 2 , 3 ) // Passes
* $mol_assert_unique( 1 , 1 , 2 ) // Fails because 1 === 1
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
*/
export function $mol_assert_unique( ... args : [ any, any, ...any[] ] ) {

for( let i = 0 ; i < args.length ; ++i ) {
for( let j = 0 ; j < args.length ; ++j ) {

if( i === j ) continue
if( args[i] === args[j] || ( Number.isNaN( args[i] as any as number ) && Number.isNaN( args[j] as any as number ) ) ) {
$mol_fail( new Error( `args[${ i }] = args[${ j }] = ${ args[i] }` ) )
}
if( !$mol_compare_deep( args[i], args[j] ) ) continue

$mol_fail( new Error( `args[${i}] = args[${j}] = ${ print( args[i] ) }` ) )

}
}

}

/**
* All arguments must be like each other (deep structural comparison).
* All arguments must be structural equal each other.
* @example
* $mol_assert_like( [1] , [1] , [1] ) // Passes
* $mol_assert_like( [1] , [1] , [2] ) // Fails because 1 !== 2
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
*/
export function $mol_assert_like< Value >( head : Value, ... tail : Value[]) {
for( let [ index, value ] of Object.entries( tail ) ) {

if( !$mol_compare_deep( value , head ) ) {

const print = ( val : any ) => {

if( !val ) return val
if( typeof val !== 'object' ) return val
if( 'outerHTML' in val ) return val.outerHTML

try {
return JSON.stringify( val, ( k, v )=> typeof v === 'bigint' ? String(v) : v,'\t' )
} catch( error: any ) {
console.error( error )
return val
}

}

return $mol_fail( new Error( `Not like (1:${ + index + 2 })\n${ print( head ) }\n---\n${ print( value ) }` ) )

}

export function $mol_assert_equal< Value >( ... args : Value[] ) {
for( let i = 1 ; i < args.length ; ++i ) {

if( $mol_compare_deep( args[0] , args[i] ) ) continue
if( args[0] instanceof $mol_dom_context.Element && args[i] instanceof $mol_dom_context.Element && args[0].outerHTML === ( args[i] as Element ).outerHTML ) continue

return $mol_fail( new Error( `args[0] ≠ args[${i}]\n${ print( args[0] ) }\n---\n${ print( args[i] ) }` ) )

}
}

export function $mol_assert_dom( left: Element, right: Element ) {
$mol_assert_equal( $mol_dom_serialize( left ), $mol_dom_serialize( right ) )
const print = ( val : any ) => {

if( !val ) return val
if( typeof val === 'bigint' ) return String(val) + 'n'
if( typeof val === 'symbol' ) return `Symbol(${val.description})`
if( typeof val !== 'object' ) return val
if( 'outerHTML' in val ) return val.outerHTML

try {
return JSON.stringify( val, ( k, v )=> typeof v === 'bigint' ? String(v) : v,'\t' )
} catch( error: any ) {
console.error( error )
return val
}

}

}
8 changes: 4 additions & 4 deletions assert/demo/demo.view.tree
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
$mol_assert_demo $mol_example_code
code? \
\$mol_assert_unique( 1 , 2 , 3 )
\$mol_assert_equal( 1 , 1 , 1 )
\$mol_assert_like( [1] , [1] , [1] )
\$mol_assert_like( { a: 1 } , { a: 1 } , { a: 1 } )
\$mol_assert_unique( [1], [2], [3] )
\$mol_assert_equal( [7] , [7], [7] )
\$mol_assert_fail( ()=> { throw Error( 'test' ) }, 'test' )
\$mol_assert_fail( ()=> { throw RangeError( 'test' ) }, RangeError )
aspects /
\Algorithm/Assert
\Testing
21 changes: 7 additions & 14 deletions assert/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,25 @@

Collection of assert functions.

**`$mol_assert_unique< Value >( ... args : Value[] )`** - all arguments must be not equal to each other.
**`$mol_assert_equal( ... args )`** - all arguments must be structural equal.

```typescript
$mol_assert_unique( 1 , 2 , 3 ) // Passes
$mol_assert_unique( 1 , 1 , 2 ) // Fails because 1 === 1
$mol_assert_equal( [1], [1], [1] ) // Passes
$mol_assert_equal( [1], [1], [2] ) // Fails because 1 !== 2
```

**`$mol_assert_equal< Value >( ... args : Value[] )`** - all arguments must be equal.
**`$mol_assert_unique( ... args )`** - all arguments must not be structural equal to each other.

```typescript
$mol_assert_equal( 1 , 1 , 1 ) // Passes
$mol_assert_equal( 1 , 1 , 2 ) // Fails because 1 !== 2
```

**`$mol_assert_like< Value >( ... args : Value[] )`** - all arguments must be like each other (deep structural comparison).

```typescript
$mol_assert_like( [1] , [1] , [1] ) // Passes
$mol_assert_like( [1] , [1] , [2] ) // Fails because 1 !== 2
$mol_assert_unique( [1], [2], [3] ) // Passes
$mol_assert_unique( [1], [1], [2] ) // Fails because 1 === 1
```

**`$mol_assert_fail( handler : ()=> any , ErrorRight? : any )`** - handler must throw an error.

```typescript
$mol_assert_fail( ()=>{ throw new Error( 'lol' ) } ) // Passes because throws error
$mol_assert_fail( ()=>{ throw new Error( 'lol' ) } , 'lol' ) // Passes because throws right message
$mol_assert_fail( ()=>{ throw new Error( 'lol' ) } , 'xxx' ) // Fails because throws left message
$mol_assert_fail( ()=>{ throw new Error( 'lol' ) } , Error ) // Passes because throws right class
$mol_assert_fail( ()=>{ throw new Error( 'lol' ) } , RangeError ) // Fails because error isn't RangeError
```
9 changes: 9 additions & 0 deletions audio/context/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace $ {
export class $mol_audio_context extends $mol_object2 {
@ $mol_memo.method
static context() {
const AudioContext = this.$.$mol_dom_context.AudioContext || this.$.$node['web-audio-api'].AudioContext
return new AudioContext()
}
}
}
4 changes: 2 additions & 2 deletions audio/demo/demo.web.view.tree → audio/demo/demo.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ $mol_audio_demo $mol_example_small
title \WebAudio API example
Beep $mol_audio_room
play => beep_play
duration 100
duration 0.1
input /
<= Beep_vibe $mol_audio_vibe
freq 440
Noise $mol_audio_room
play => noise_play
duration 1000
duration 1
input /
<= Noise_vibe $mol_audio_vibe
freq <= noise_freq 440
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ $mol_audio_demo_vibe $mol_example_small
sub /
<= List $mol_list rows /
<= Duration $mol_labeler
title <= duration_label \Duration, ms
title <= duration_label \Duration, s
content /
<= Duration_num $mol_number
precision_change 50
value? <=> duration? 500
precision_change 0.05
value? <=> duration? 0.5
<= Frequency $mol_labeler
title <= frequency_label \Frequency, Hz
content /
Expand All @@ -28,7 +28,7 @@ $mol_audio_demo_vibe $mol_example_small
Filter null
value? <=> shape? null
options /$mol_audio_vibe_shape
\sine
\sine
\square
\sawtooth
\triangle
Expand Down
File renamed without changes.
20 changes: 20 additions & 0 deletions audio/gain/gain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace $ {

export class $mol_audio_gain extends $mol_audio_node {

@ $mol_mem
override node_raw() { return this.context().createGain() }

@ $mol_mem
override node() {
const node = super.node()
node.gain.setValueAtTime( this.gain(), this.time() )
return node
}

@ $mol_mem
gain( next = 1 ) { return next }

}

}
19 changes: 0 additions & 19 deletions audio/gain/gain.web.ts

This file was deleted.

Loading

0 comments on commit 793f0bf

Please sign in to comment.