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

raml-outline

v0.0.16

Published

[![Build Status](https://travis-ci.org/mulesoft/raml-outline.svg?branch=code)](https://travis-ci.org/mulesoft/raml-outline)

Downloads

5

Readme

raml-outline

Build Status

This is a central place for RAML outline.

Getting Started

import ramlOutline = require("raml-outline")

//intializing AST provider and outline generally

var astProvider = {
                  
  getASTRoot() {
    ...
  },
  
  getSelectedNode() {
      ...
  }
}

ramlOutline.setASTProvider(astProvider);
ramlOutline.initialize();

//Adding category filters, which split nodes into categories

var ResourcesCategory = "ResourcesCategory"
var SchemasAndTypesCategory = "SchemasAndTypesCategory"
var ResourceTypesAndTraitsCategory = "ResourceTypesAndTraitsCategory"
var OtherCategory = "OtherCategory"

function isResource(node) {
    ...
}
function isSchemaOrType(node) {
    ...
}
function isResourceTypeOrTrait(node) {
    ...
}
function isOther(node) {
    ...
}

ramlOutline.addCategoryFilter(ResourcesCategory, isResource);
ramlOutline.addCategoryFilter(SchemasAndTypesCategory, isSchemaOrType);
ramlOutline.addCategoryFilter(ResourceTypesAndTraitsCategory, isResourceTypeOrTrait);
ramlOutline.addCategoryFilter(OtherCategory, isOther);

//adding decorations to node types

ramlOutline.addDecoration(ramlOutline.NodeType.ATTRIBUTE, {
    icon: UI.Icon.ARROW_SMALL_LEFT,
    textStyle: UI.TextClasses.NORMAL
});

ramlOutline.addDecoration(ramlOutline.NodeType.RESOURCE, {
    icon: UI.Icon.PRIMITIVE_SQUARE,
    textStyle: UI.TextClasses.HIGHLIGHT
});

...

// Now at any point for any category we can ask for a subtree and convert it to JSON

var resourceCategoryOutline = ramlOutline.getStructure(ResourcesCategory).toJSON()

//each node contains:
//resourceCategoryOutline.text - Node label text to be displayed.
//resourceCategoryOutline.typeText - Node type label, if any.
//resourceCategoryOutline.icon - Node icon, set using node type based decorations, or directly via Decorator
//resourceCategoryOutline.textStyle - Node test style, set using node type based decorations, or directly via Decorator
//resourceCategoryOutline.key - Unique node identifier, is set if there is key provider assigned. 
//resourceCategoryOutline.start - Node start position.
//resourceCategoryOutline.end - Node start position.
//resourceCategoryOutline.selected - Whether the node is selected.
//resourceCategoryOutline.category - Node category.
//resourceCategoryOutline.children - Node children.

Code highlights

Outline core

setASTProvider method sets AST provider to feed outline with parser data.

addCategoryFilter method creates new category, provided the name and a node filtering method.

addDecorator method sets up a new decorator, being able to provide icon and text style for the node.

addLabelProvider method sets up a new label provider, being able to provide label and type text for the node.

setVisibilityFilter method sets up a way to filter out nodes, which should not be visible.

setContentProvider method sets up a way to convert AST tree to outline tree. Not recommended to override the default content provider.

setKeyProvider if set, will be asked to provide an unique key for each node.

getStructure method returns outline tree for the specified category, or in general. getStructureForAllCategories method returns the map from category name to the category sub-tree.

Defaults

Defaults module simplify outline usage by not making the user to implement decorators, label providers etc.

Defaults module provide outline with default label provider, key provider, visibility filter, and decorator, which is based on simplified decorations.

Besides setting AST provider, user should set up categories if needed, and add static decorations for node types like this:

ramlOutline.addDecoration(ramlOutline.NodeType.ATTRIBUTE, { icon: UI.Icon.ARROW_SMALL_LEFT, textStyle: UI.TextClasses.NORMAL });

ramlOutline.addDecoration(ramlOutline.NodeType.RESOURCE, { icon: UI.Icon.PRIMITIVE_SQUARE, textStyle: UI.TextClasses.HIGHLIGHT });

Here, node type is one of the supported node types list, and icon and textStyle are arbitrary strings, which will then be put into the respective node fields.