npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@feecting/deva

v1.0.26

Published

The Deva Core

Downloads

10

Readme

DEVA

Deva is a lightweight class object that provides events and object management with inherited properties.

Install

$> npm i @feecting/deva

Basic Structure

// include the main Deva class
const Deva = require('feecting/deva');

// setup the Deva object
const deva = new Deva({
  agent: {
    uid: '*uinique identifier*'
    key: '*DEVA KEY*',
    name: '*DEVA NAME*',
    describe: '*DEVA LONG DESCRIPTION*',
    prompt: {
      emoji: '🐶',
      text: '*DEVA*',
      color: 'white',
    },
    voice: {
      speech: 'Alex',
      speed: 1
    },
    profile: {
      emoji: 'the graphic emoji the agent travels with. 50px x 50px'
      avatar: 'the graphic avatar the agent travels with 150px x 150px',
      background: 'a background asset for page displays for th eagent',
      describe: 'the profile description for the agent that is used in displays.',
      gender: 'the preferred gender string for the agent',
    },
    translate(input) {
      return input.trim();
    },
    parse(input) {
      return input.trim();
    }    
  },
  vars: {},
  listeners: {},
  modules: {},
  func: {},
  methods: {},
  deva: {},
  onStart() {},
  onStop() {},
  onEnter() {},
  onExit() {},
  onDone() {},
  onInit() {},
});

// initialize the class
deva.init();

Breakdown

Agent

this.agent

The "me" object contains the profile information for the DEVA.

Data Attributes
  • uid: The unique id for the Deva.
  • key: The unique key for the Deva.
  • name: The name of the Deva.
  • description: A description of what the Deva does.
  • prompt: Define how prompt displays.
    • emoji: The emoji for use as a prompt indicator.
    • text: Short text for prompt display.
    • color: The color of the prompt for the Deva.
  • voice: Voice properties of the Deva.
    • speech: The name of the voice speech to use.
    • speed: The speed of the voice.
  • profile: Public Profile Information
    • emoji: The emoji for the Deva
    • avatar: The avatar for the Deva
    • background: The background image for the Deva
    • gender: The gender of the Deva
    • describe: A short description of the deva 100 characters or less.

Vars

this.vars

The vars can be use to set local variables for the deva that need to be used in your program.

There are no default variables, so the scope is for you and your imagination to figure out.

Example
...
  vars: {
    foo: 'bar',
    steps: 10,
    strings: 'Some variable string',
    adding: 1 + 9 + 11,
    objects: {
      key: 'key value'
    },
    arrays: [
      'value 1',
      'value 2',
    ]
  }
...

Listeners

Listeners are what you setup that allow your Deva to communicate with other Deva or parts of your application/system.

this.listeners

Default Listeners

Each Deva comes with a set of default listeners to provide basic functionality.

Question

The question event is the functionality that exposes the methods to the outside world. When a deva asks a question the string is parsed into a question format so that commands to access various methods can be exposed.

const question = await this.question(`#*agent_key* *method*:*params* *question string*`);
Start

This will trigger an event to start the Deva.

this.talk(`*agent_key*:start`);
Stop

This will trigger an event to stop the Deva.

this.talk(`*agent_key*:stop`);
Status

This will trigger an event to broadcast the Deva status.

this.talk(`*agent_key*:status`);

Deva

this.deva

The main object for Deva that are bwlow this Deva.

Modules

The external modules that your Deva might require to function.

this.modules

Func

The functions that your deva uses to operate. Functions are not exposed through the api to public access.

this.func

Methods

this.methods

The methods are exposed publicly through the question event that parses a string and sends a request to the question method that then interacts with functions, modules, and variables.

State Functions

Provided are a set of state functions that trigger when a Deva is at various states of starting/stopping.

onStart()

The onStart() function runs after the start function has completed.

this.onStart() {
  // some code to run when the deva starts.
}

onStop()

The onStop() function runs after the stop function has completed.

this.onStop() {
  // some code to run when the deva stops
}

onEnter()

The onEnter() function runs after the enter event has fired.

this.onEnter() {
  // some code to run when the deva is loaded
}

onExit()

The onExit()function runs after the exit event has fired.

this.onExit() {
  // some code to run when the deva logs out.
}

onDone()

The onDone()function runs after the done event has fired.

this.onDone() {
  // some code to run when the deva logs out.
}

onInit()

The onInit() function runs after the init() function has completed.

this.onInit() {
  // some code to run when the Deva initializes.
}

Utility Functions

uid()

Generates a unique ID that is used in packet transfer and other various ways.

this.uid() // inside the object
deva.uid() // outside the object

// example
this.vars.id = this.uid()

talk(evt, resource=false)

The talk() function is used when your Deva needs to broadcast an event that other Deva or functions would be listening for.

this.talk('event', resource);  // inside the object
deva.talk('event', resource); // outside the object

// example
const evt_id = this.uid();
const evt_data = {
  task_id: 1,
  task_name: 'this is blank data',
  task_contact: '[email protected]',
};

this.talk('big-event', {
  id: evt_id,
  key: this.me.key,
  q: {
    bot: this.me,
    text: 'text to send to the event',
    data: evt_data,
  },
  created: Date.now(),
});

listen(evt callback)

The listen function can assign listeners to the Deva and designate which callback function to run when an event is fired.

Listeners can be set up individually this way or also added to the listeners object independently.

this.listen('some-event', this.func.listener);

this.func.listenter = packet => {
  console.log('some-event-fired');
};

once(evt, callback)

The once() function can assign a one-time listener to a function. This is useful when returning data with an id that one Deva has submitted to another Deva. Also very useful for submit responses that are unique to the request.

this.once(`some-once-event`, this.func.listener)
this.func.listener = packet => {
  console.log('some-once-event-fired');
}

ignore(evt, callback)

The ignore() function removes a listener from the designated event. This is useful for adding and removing events dynamically or as needed.

this.ignore('ignore-event', this.func.listener);
this.func.listener = packet => {
  console.log('ignore-event-fired');
}

Load(agent, opts)

To add a Deva dynamically use the load() function. This can be utilized to add Deva to an existing Deva after the object has already been created.

const opts = {
  me: {...},
  vars: {...},
  listeners: {...},
  deva: {...},
  func: {...},
  onStart() {},
  onStop() {},
  onEnter() {},
  onExit() {},
}
this.load('deva-name', opts);

unload(agent)

To delete a Deva for any reason use unload(). This will delete the Deva and all it's parts from the current Deva.


this.unload('deva-key');

question(packet)

The question(packet) function is a default function that allows the system to ask questions of itself or other Deva.

The function checks the beginning of a string for a # to determine wether to issue a command to run a specific method.

See Question Listener for usage.

#deva method:params message

status()

The status() function will return the running status of the current Deva.

start()

The start() function will start the Deva and run the onStart() state function.

stop()

The stop() function will stop the Deva and run the onStop() state function.

init(deva=false)

The init() function will initialize the Deva and run the onInit() state function.

initDeva()

The initDeva() function will initialize the Deva located under the current Deva set. To be used in instances of a main Deva parent situation.

©2021 Quinn Michaels; All Rights Reserved.