New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

olaf-loader

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

olaf-loader

A Webpack loader for the Olaf language.

latest
Source
npmnpm
Version
1.1.5
Version published
Maintainers
1
Created
Source

Olaf Loader

olaf-loader is a Webpack loader for Olaf, a playful and simple programming language inspired by the beloved snowman from Disney's Frozen. With this loader, you can easily compile Olaf code into JavaScript, making it easy to integrate Olaf into your Webpack projects.

Features

  • Fun and Simple Syntax: Olaf uses intuitive and fun syntax, making programming easier and more enjoyable.
  • Seamless Webpack Integration: Use the olaf-loader to automatically compile Olaf code into JavaScript during your Webpack build process.
  • Object-Oriented Support: Define classes and use constructors to structure your code.
  • Asynchronous Handling: Simulate asynchronous operations with the wait keyword.
  • Error Handling: Olaf comes with built-in checks for common syntax errors, ensuring a smooth development experience.
  • String Interpolation: Use ${expression} for string interpolation
  • Comments Support: Both single-line (//) and multi-line (/* */) comments
  • Source Maps: Built-in source map support for better debugging
  • Constant Variables: Use freeze keyword for constants
  • Array Methods: Enhanced array operation support
  • Default Parameters: Support for default function parameters

Getting Started

Prerequisites

  • Node.js (version 12 or higher)
  • Webpack (version 5 or higher)

Installation

To install olaf-loader and use it in your Webpack project, run the following command:

npm install olaf-loader --save

Sample Code

build checkNumber(num):
    if num > 0:
        say num + " is positive."
    else:
        if num < 0:
            say num + " is negative."
        else:
            say num + " is zero."
        end
    end
end

build doubleNumbers(numbers):
    return numbers.map(number => number * 2)
end

build filterEvens(numbers):
    return numbers.filter(number => number % 2 == 0)
end

build printNumbers(arr):
    for each num in arr:
        say num
    end
end

snowman Animal:
    build constructor(name):
        this.name = name
    end

    build makeSound(sound):
        say this.name + " says " + sound
    end
end

build main:
    snowball nums = [-1, 0, 1, 5, -10]

    say "Checking Numbers:"
    for each number in nums:
        checkNumber(number) // Calling the function to check each number
    end

    say "Original Numbers:"
    printNumbers(nums) // Invoke to print original numbers

    snowball doubled = doubleNumbers(nums) // Call to doubleNumbers function
    say "Doubled Numbers:"
    printNumbers(doubled) // Invoke to print doubled numbers

    snowball evens = filterEvens(nums) // Call to filterEvens function
    say "Even Numbers:"
    printNumbers(evens) // Invoke to print even numbers

    snowball dog = new Animal("Sven")
    dog.makeSound("woof")

end

main()

Compiled JavaScript Code

function checkNumber(num) {
  if (num > 0) {
    console.log(num + " is positive.");
  } else {
    if (num < 0) {
      console.log(num + " is negative.");
    } else {
      console.log(num + " is zero.");
    }
  }
}

function doubleNumbers(numbers) {
  return numbers.map((number) => number * 2);
}

function filterEvens(numbers) {
  return numbers.filter((number) => number % 2 == 0);
}

function printNumbers(arr) {
  for (const num of arr) {
    console.log(num);
  }
}

class Animal {
  constructor(name) {
    this.name = name;
  }

  makeSound(sound) {
    console.log(this.name + " says " + sound);
  }
}

function main() {
  let nums = [-1, 0, 1, 5, -10];

  console.log("Checking Numbers:");
  for (const number of nums) {
    checkNumber(number); // Calling the function to check each number
  }

  console.log("Original Numbers:");
  printNumbers(nums); // Invoke to print original numbers

  let doubled = doubleNumbers(nums); // Call to doubleNumbers function
  console.log("Doubled Numbers:");
  printNumbers(doubled); // Invoke to print doubled numbers

  let evens = filterEvens(nums); // Call to filterEvens function
  console.log("Even Numbers:");
  printNumbers(evens); // Invoke to print even numbers

  let dog = new Animal("Sven");
  dog.makeSound("woof");
}

main();

Execution result:

Checking Numbers:
-1 is negative.
0 is zero.
1 is positive.
5 is positive.
-10 is negative.
Original Numbers:
-1
0
1
5
-10
Doubled Numbers:
-2
0
2
10
-20
Even Numbers:
0
-10
Sven says woof

Advanced Features (v1.2+)

Switch/Case Statements (blizzard/case)

Olaf supports switch/case statements using blizzard and case keywords:

blizzard(expression):
  case value1:
    // statements
    break
  case value2:
    // statements
    break
  else:
    // default statements
end

Ternary Operator (snowif)

Use the snowif keyword for ternary expressions:

snowball result = snowif(condition, valueIfTrue, valueIfFalse)

Try/Catch Error Handling (igloo/catch)

Handle errors with igloo and catch:

igloo:
  // try block
catch(error):
  // catch block
end

Arrow Functions (frost)

Arrow functions can be defined using the frost keyword:

frost double = (x) => x * 2

Module Imports/Exports (sled/export)

Import and export modules:

sled { something } from "./module.olaf"
export default myFunction

Destructuring (snowgrab)

Destructure objects easily:

snowgrab { a, b } = obj

String Interpolation (Frosty Quotes)

Use backticks and ${} for string interpolation:

say `Hello, ${name}!`

Custom Operators (flakeop)

Define custom operator functions:

flakeop add = (a, b) => a + b

VSCode Integration

Olaf supports VSCode extension for IntelliSense, Code snippets, and syntax highlighting.

GitHub
VSCode Extension repository
NPM registry
Syntax Highlighter Extension for VSCode

Keywords

webpack

FAQs

Package last updated on 18 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts