How to turn a .ts file into a GitHub extension

I have a .ts file here (Thanks @richard):

//% blockNamespace=Random color="#FF8000"
class FastRandomBlocks {
    _rng: Math.FastRandom

    constructor(seed: number) {
        this._rng = new Math.FastRandom(seed)
    }

    /**
     * Return the next number between 1 and 65535
     */
    //% block="$this get next number"
    //% this.defl=rng
    //% blockId="fastrandomblocks_nextnumber"
    nextNumber() {
        return this._rng.next()
    }

    /**
     * Returns a random number between two numbers
     * @param minimum The minimum number, ex: 1
     * @param maximum The maximum number, ex: 10
     */
    //% block="$this get a random number between $minimum| and $maximum"
    //% inlineInputMode=inline
    //% this.defl=rng
    //% blockId="fastrandomblocks_randomrange"
    randomRange(minimum: number, maximum: number) {
        return this._rng.randomRange(minimum, maximum)
    }

    /**
     * Returns a boolean based on the percent passed in
     * @param percent The percentage of the time the boolean returned will be true.
     */
    //% block="$this get a random boolean with %percent| percent chance"
    //% this.defl=rng
    //% blockId="fastrandomblocks_percentchance"
    percentChance(percent: number) {
        return this._rng.percentChance(percent)
    }

    /**
     * Returns a boolean with a 50% chance of being true
     */
    //% block="$this 50/50 chance"
    //% this.defl=rng
    //% blockId="fastrandomblocks_randomboolean"
    randomBoolean() {
        return this._rng.randomBool()
    }

    /**
     * Pick a random element from the array passed in
     * @param elements The array to choose from, ex: ["apples", "oranges", "pears"]
     */
    //% block="$this choose a random element from %elements"
    //% elements.shadow="lists_create_with"
    //% this.defl=rng
    //% blockId="fastrandomblocks_randomelement"
    randomElement(elements: any[]) {
        return this._rng.pickRandom(elements)
    }

    /**
     * Reset the RNG
     */
    //% block="Reset $this"
    //% this.defl=rng
    //% blockId="fastrandomblocks_resetrng"
    resetRNG() {
        this._rng.reset()
    }
}


//% color="#FF8000"
namespace Random {
    /**
     * Create a RNG object
     * @param seed The seed for the RNG, ex: 1234. Using 0 as the seed may have unexpected results!!!
     */
    //% block="create RNG || with seed $seed"
    //% blockSetVariable=rng
    //% expandableArgumentMode="toggle"
    //% blockId="random_createrng"
    export function createRNG(seed: number = null): FastRandomBlocks {
        return new FastRandomBlocks(seed);
    }
}

How can I turn it into a GitHub extension so that people can just import my extension with the GitHub URL?

Just create a project with this code then press the github button at the bottom of the editor. It should create a repo for you that people can import. There’s also a test button in the github page to try it out.

1 Like

More info: https://arcade.makecode.com/github/getting-started

1 Like

Thanks! I did not know it was that easy!

Here is the repo if anyone is interested:

1 Like

@UnsignedArduino if you make a new post with the extension and how to use it, I’ll add the extension tag to it!

2 Likes