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

bala-exp

v1.0.3

Published

The Expression Manager is a js module that provides functionality for parsing and highlighting expressions in a text editor or text area. It can be used to provide suggestions to users while they are typing identifiers, function names, and suffixes in an

Downloads

1

Readme

Expression Manager Node Module

The Expression Manager is a js module that provides functionality for parsing and highlighting expressions in a text editor or text area. It can be used to provide suggestions to users while they are typing identifiers, function names, and suffixes in an expression.

Installation

To use the Expression Manager in your project, you need to install it using npm. Open your terminal or command prompt and run the following command:

  npm install survey-exp-manager

Usage

To use the Expression Manager, you need to import the createExpressionManager function from the module. It takes an object as an argument with the following properties:

placeholder (optional): The placeholder text to be displayed in the text editor when it is empty.
readOnly (optional): A boolean value to specify if the text editor should be read-only or editable. Default value is false.
identifiers (optional): Object containing all the different identifiers that can be written in the expression
 Format: { name: { description: "Description text" } }
options:   1. description (String) - Description to shown for the identifier in suggestion
  2. suggestionOnly (Bool) - The identifier will only be used for showing suggestions (if true)
  3. displayFor (String) - Match string for which the identifier can be shown in the suggestion
  4. hideFor (String) - Match string for which the identifier should not be shown in the suggestion
  5. returnType (*) - Type of the value the variable can have during runtime
  6. customHTML (String) - Custom text to be shown instead of the name
expFunctions (optional): Functions to be supported inside the autocomplete field textBox: The text area or text editor element that you want to attach the Expression Manager to.
suffixes (optional): These will be displayed in the suggestion when the user types a "." Anything that the user types after the "." will be considered a suffix and the corresponding list will alone be searched.

Listeners

The suggestionListener emits three parameters:
helpFor: This refers to the element for which suggestions need to be shown. currentSuggestions: It represents a list of suggestions (identifiers, suffixes, and expFunctions) that are matched for the element specified by the helpFor. activeSuggestionIndex: It represents the index of the currently active suggestion in the currentSuggestions list.

Here is an example of how to use the Expression Manager:

  import { createExpressionManager, expFunctions } from 'expression-manager';

  // Get the text area element
  const textBoxElement = document.getElementById('myTextArea');

  // Define identifiers, expression functions, and suffixes (optional)
  const identifiers = { 
      // ... 
  };
  const expFunctions = expFunctions;
  const suffixes = {
      // ...
  };

  // Create the Expression Manager
  const expressionManager = createExpressionManager({
      placeholder: 'Type your expression here...',
      readOnly: false,
      identifiers,
      expFunctions,
      textBox: textBoxElement,
      suffixes,
  });

  // Listen for events (optional)
  expressionManager.on('onFocus', (expression) => {
      // Handle focus event
  });

  expressionManager.on('onBlur', (expression) => {
      // Handle blur event
  });

  expressionManager.on('suggestionsListener', ({ currentSuggestions, helpFor, activeSuggestionIndex }) => {
      // Handle suggestion changes
  });

  expressionManager.on('updateSuggestionIndex', (activeIndex) => {
        // Handle suggestion index
  });
  // You can also update identifiers or read-only mode dynamically
  expressionManager.updateIndentifier(identifiers);
  expressionManager.updateReadOnly(true);

  // To remove the change listener
  expressionManager.removeChangeListener();

Dependencies

The Expression Manager has the following dependencies, which will be automatically installed when you install the module:

events: Node's event emitter for all engines.

acorn-loose: This parser will parse any text into an ESTree syntax tree that is a reasonable approximation of what it might mean as a JavaScript program.

acorn-walk: An abstract syntax tree walker for the ESTree format.

License

This project is licensed under the MIT License - see the LICENSE file for details.