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

magma-script

v1.4.1

Published

Magma Script Language

Downloads

10

Readme

Magma Script Language

Magma Translator to JavaScript

How to use it?

const MagmaScript = require('magma-script')

new MagmaScript({
    input: __dirname + '/target.mg',
    output: __dirname + '/bundle.js',
    std: true, // Defualt (true)
    strict: true, // Default (true)
    bundle: true, // Default (true)
    global: false, // Default (false)
    root: '/usr/bin/node/', // Default ('/usr/bin/node/')
    beautify: true // Default (true)
})

Flags:

  • input - Specify full path to your MagmaScript file
  • output - Specify full path if you want to save file (optional)
  • std - If you want to include Magma's Standard Library to this file (optional)
  • strict - If you want to append 'use strict' to the file (optional)
  • bundle - If you want to bundle all non-node files included in this script and it's descendants (optional)
  • global - If you want to insert #!/usr/bin/env node header before
  • root - If you want to use different Node.js compiler
  • beautify - If you want to beautify the output code

What if I don't want to write to a file?

let data = new MagmaScript({
    input: __dirname + '/target.mg'
}).result

// 'data' now contains the translated MagmaScript file

You can also compile the entire directory using this syntax

new MagmaScript.Directory({
    input: __dirname + '/src',
    output: __dirname + '/out',
    std: 'main.mg', // Default (null)
    strict: true // Default (true)
})

// Every .mg file will be translated and written to specified directory

This package comes with Magma-to-JS compilator

All you need to do is to install this package globally:

$ npm install magma-script -g

Here are some usage examples:

# Possible commands:
# mg <input file> <output file>
# mg help


$ magma-script input.mg output.js

# Or:

$ mg input.mg output.js

Flags:

  • input - Specify full path to your MagmaScript files folder
  • output - Specify full path to directory where you want to save translated files
  • std - File name of main Magma source file to which Standard Library will be attached (optional)
  • strict - If you want to append 'use strict' to all the files (optional)

However if you want to bundle all the files into one standalone, please use the base MagmaScript class compiler with flag 'bundle' turned as true

Example MagmaScript Code

import { remote } from 'electron'

let arr = [1, 3, 4]
let i = 0

export i

// For loop
loop item in arr {
    console.log(item)
}

// For loop (index, value)
loop index, value in arr {
    // You can interpolate variables inside of a regular string
    console.log('index ${index}, value ${value}')
}

// While loop
loop (arr.lenght > i) {
    i++
}

// While True loop
loop {
    console.log('again and...')
}



// Object Structure
tree myObject {
    age = 18
    name = 'John'
}

// Function (type is optional)
fun void add(a, b) {
    return a + b
}

// Class (setup function is constructor)
> Hero {
    setup(obj) {
        this.name = obj.name
    }
}

// Class with inheritance
> Mummy : Granny {
    setup(obj) {
        super(obj)
    }
}

Standard Library Functions


// // In Browser Only:
let el = element('#id') // document.querySelector('#id')
let els = elements('.class') // document.querySelectorAll('.class')
el.css('border-radius', '10px') // el.style.borderRadius = '10px'
el.parent(3) // Returns parent 3 elements up in hierarchy

// Event Listeners
el.on('click', () => log('Hello!')) // Add Event Listener

// Get id of the event listener
let id = el.on('click', () => {
    log('Clicked!')
})

el.detach('click', id) // Remove 'click' event listener with the specific ID
el.detach('click') // Removes all 'click' event listeners



// // Everywhere:
log('Hello World') // console.log('Hello World')
random(5, 10) // (Math.random() * 10) + 5
sqrt(64) // Math.sqrt(64)
log('HELLO'.lower(), 'world'.upper()) // logs: hello WORLD
log('john'.firstUpper()) // logs: John
log('Fun'.firstLower()) // logs: fun

let arr = [1, 2, 3]

arr.last() // arr[arr.length - 1]

// The standard library is going to be expanded soon

Note:

Writing vanilla JavaScript in MagmaScript is valid.

Thank you for using this package.