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

@nlpjs/core

v4.26.1

Published

Core

Downloads

68,884

Readme

NLPjs logo

@nlpjs/core

Coverage Status NPM version NPM downloads

TABLE OF CONTENTS

Installation

You can install @nlpjs/core:

    npm install @nlpjs/core

Container

The Container is an IoC container class. Basically it's able to store instances and classes, marked as being singleton or not. When a class is registered as a singleton, a new instance is created and everytime that the container is asked for this class the same instance is returned. Same behaviour if we register an instance as singleton, but in this case this instance is returned always. When an instance is registerd as not singleton, the class of the instance is stored and when asked to the container it returns a new instance of this class.

Also in the container can be registered settings with the name of the objects registered, so these settings are provided to the new created instances.

And also pipelines can be registered. Pipelines are sequences of commands that are executed based on the classes and instances known by the container.

Plugins

At the plugins folder you will find some different classes with atomics tasks:

  • split: given an object with a property text, split this text into an array of characters into the property splitted
  • reverse: given an object with a property splitted that is an array, reverse this array
  • join: given an object with a property splitted that is an array, join this array into an string into the property text
  • lower: given an object with a property text, convert this string to lower case.
  • upperFirst: given an object with a property text, convert the first character to upper case

Pipelines

If you take a look at the pipelines.md file you'll see this:

# Pipelines

## reverse
split
reverse
join
->output.text

## reverse-and-*
$reverse
lower
->output.text

## reverse-and-capitalize
$super
upperFirst
output.text

reverse, reverse-and-$ast and reverse-and-capitalize are pipelines. Each one contains commands to be executed in sequence. As you can see, the commands are the name of the plugins, except some exceptions:

  • output.text: this is telling that at this step take a look at the output object (the one that is returned by the previous step) and from it extract the property text before going to the next step
  • $reverse: When you start a name with the $ that means not to execute a plugin but to call another pipeline using as input the current output.
  • $super: This is to call the parent. You can see that reverse-and-&ast have an asterisk at the end, this is a wildchar, so will be the parent of those pipelines that match this pattern, in this case reverse-and-capitalize match this name so if a child pipeline.
  • ->output.text: when a command starts with the -> that means that this command should be executed only if this pipeline is the one executed directly, but not when this pipeline is invoked from another pipeline. So when calling reverse the output will be an string, but when calling reverse from reverse-and&ast this last command will be not execute so the output of reverse will be the object and not the string.

Creating a container

This is the way of creating a bootstrapped container:

const { containerBootstrap } = require('@nlpjs/core');
const container = containerBootstrap()

This automatically will:

  • load the .env file if exists as environment variables
  • load the conf.json file if exists as configuration (will be explained in other example).
  • If the conf.json file does not exists or it does not includes a pipelines path, then load the ./pipelines.md by default as pipelines
  • If the conf.json file does not exists or it does not includes a plugin path, then load the content of the folder ./plugins as plugins.

Executing a pipeline

Containers have a method runPipeline where you can pass the name of the pipeline (or the compiled pipeline) and an input to be processed. Important: this input usually travel through each step of the pipeline, so can be modified by the pipeline execution. This is an example of code calling the pipeline reverse-and-capitalize, that shows how to do inheritance of pipelines, call other pipelines, and have commands that are only executed if the depth of the call is 0 (belongs to the called pipeline).

const { containerBootstrap } = require('@nlpjs/core');

async function main() {
  const container = containerBootstrap();
  const input = 'GNIHTEMOS';
  const result = await container.runPipeline('reverse-and-capitalize', input);
  console.log(result); // It should log "Something"
}

main();

Example of Usage

You'll find an example of usage at examples/01-container

Contributing

You can read the guide of how to contribute at Contributing.

Contributors

Contributors

Made with contributors-img.

Code of Conduct

You can read the Code of Conduct at Code of Conduct.

Who is behind it?

This project is developed by AXA Group Operations Spain S.A.

If you need to contact us, you can do it at the email [email protected]

License

Copyright (c) AXA Group Operations Spain S.A.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.