open-index/open-npm huggingface dataset:
npm package: @metomic/alias-core
Description: ## What is this? Client-side (web) javascript library and UI elements that create a metomic alias for a given email.
Latest version: 0.3.0

# alias-core

## What is this?
Client-side (web) javascript library and UI elements that create a metomic alias for a given email.

## When should I use it?
Probably only if you're writing a library that provides metomic alias functionality in your chosen framework.

For an example, see @metomic/alias-react

## How do I use it?
You probably don't want to - there's likely a higher level library. But if you're sure:

### importing
```javascript
import {
  Alias, 
  EncryptionOverlay,
  AliasToggle
} from '@metomic/alias-core
```

### constructing an alias (no ui)
```javascript
Alias({ appId: 'zx123' }).secure("an-email@somewhere.com")
  .then( ... )
```

### mutably binding to an input element
```javascript
const run  = Alias.dom.bindToInput(appId, purpose, inputElement, (state) => {
  /* optional state-change callback here. Options:
   state = { status: 'loading' }
   state = { status: 'error', error: 'error' }
   state = { status: 'complete', result: 'alias@metomic' }
   state = { status: 'reset', result: 'original-email' }
  */
})

run(true) // performs securing action on input
run(false) // reverts securing action on input
```

### manually managing entire flow
```javascript
  const overlay = Alias.dom.createOverlayController(inputEl)
  const { doToggle } = createSecuringContext(appId, purpose, inputEl, function onStateChange(state){
    // deal with states
    overlay.setActive(state === 'loading')
  })


  doToggle(true) // triggers securing action on input
  doToggle(false) // reverts securing action on input
  
```