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

thulejs-scopes

v1.0.2

Published

Reads all .js and .mjs files in scopes and parses functions, classes and arrow functions

Downloads

135

Readme

ThuleJS-Scopes

Managing scopes containing functions and classes.


ES6/Module styled | functions and classes distribution throughout your application.

The why is power:
I needed a place for my tools. If it's more than a tool, it should be a module.

--with love, quirks and glitches, Idiosyncratics

Get thulejs-scopes

npm install thulejs-scopes

See example
Example included in the repository.

Usage
Add an scopes directory to your project root and place here .js or .mjs files.
The directory structure will be identical to scopes structure.

Import the module and add the config:

import scopes from 'thulejs-scopes';
new scopes();

That's it!, your scopes content is now available.

Get, Find, Build commands

Get commands to view your scopes meta.
returns an information object

// returns the name/version/settings of scopes:
scopes.getMeta();

// returns an warning if scope is not loaded

// get the scope meta:
scopes.getMeta('std')

// Get meta in <parent> from <scope>
scopes.getMeta('customScript', 'xml'))          

Find commands to retrieve scopes from cache.
returns an scope object
Provides a safe way to retrieve the scopes.

// must have scopename, returns a warning
scopes.findScopes()                       

// returns an warning if scope is not loaded

// get the first found scope in the structure
scopes.findScopes('xml')                  

// if a double name exists in the scope and you want to specify:
// from <parent> get <scopename>

scopes.findScopes('myModule', 'xml')    

Get commands to return scopes content.
returns an scope object
Will pull from file if not preload or cached (new object)

// returns the entire scopes content:
// by default preload is disabled, a warning is returned.
scopes.getScopes()

// get the first found scope in the structure:
scopes.getScopes('std')

// get these two scopes, first found:
scopes.getScopes('std', 'utils')

// in this example 'utils' will contain mulitple scopes

Build commands to rebuild and cache scopes.
returns a message
Will pull from file if not preload or cached. Scope is then cached

// rebuild the entire scope if preload
scopes.buildScopes()        
                        
// must have scopename, a warning is returned
scopes.buildScopes('std')

// rebuild scope from file, specify from <parent> get <scopename>                           
scopes.buildScopes('customScript', 'xml')           

Pre-loading scopes:

By default the preload is disabled.
If you use preload, all scopes are loaded at start, responses after are better as imports are already done.
Use the build commands to build and cache scopes. getScope() will use cached items if available.
So if you care more about speed or memory consumption, this offers some flexibility.


Options and settings

Set ThuleJS-scopes options:

Pass an options object:

new scopes();

// -or-

const scopesOptions ={
    path: '',
    dir: '',
    preload: true
}
new scopes(scopesOptions);

By default if no scopes path and/or dir is given, it will look for 'scopes' in the app root directory.
In previous versions a scopes directory was created if not present, however this practice is discontinued and an error is thrown instead.

Scope usage example

Also see the examples in the repository.
Functions, classes and arrow functions must be closed with //|| or #checked.
For functions #function, for classes #class and for arrow functions #arrow

function myFunction (...args){

}//#checked


function myFunction (..args){

}//||

function myFunction (...args){

}//#function

class myClass {

}//#class


const square = x => x * x //||

const function = (test) => { console.log("An arrow function."); }//#checked

const add = (a, b) => a + b //#arrow

The functions are parsed through an AST (abstract syntax tree) to validate the function by Acorn.
Invalid functions are skipped.

Scope file repository

The only thing parsed are .js and .mjs, however all files will have their filepaths stored in the scopes.