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

swizzler

v0.0.5

Published

TypeScript DSL for building expressions which can be compiled to TypeScript, Javascript and GLSL.

Downloads

10

Readme

swizzler Continuous Integration License FOSSA Status Renovate enabled

TypeScript DSL for building expressions which can be compiled to TypeScript, Javascript and GLSL.

Design

As much as possible, this library mimics the feature set of GLSL (targeting WebGL, first generation). The full set of functionality can be found by inspecting the exported types.

Inputs are declared using reference (for dynamic values) and float, int, etc. (for static values). Most other exports mimic the operators (add, subtract, etc.) and functions (sin, abs, etc.) built into GLSL - though note that they manipulate logic, not values. You must compile the expression tree to source code (compileTypeScript, compileGlsl, etc.) to execute it.

The generated code will often include multiple statements. A prefix is given for the final statement, allowing it to either be assigned to a variable, returned or given as an argument to a function, for example.

The more logic can be included in a single compilation, the better a job can be done in the constant folding and optimization processes.

Although TypeScript requires that the values returned by reference, subtract, etc. are visible to you, they are not intended for use other than to pass to other functions from this library and are likely to significantly change.

Example

Input

import {
  reference,
  float,
  vec2,
  multiply,
  dot,
  subtract,
  add,
  compileTypeScript,
  compileJavascript,
  compileGlsl,
} from "swizzler";

const argumentA = reference("vec3", "testArgumentA");
const argumentB = reference("float", "testArgumentB");

const expression = subtract(
  argumentB,
  add(
    argumentA,
    dot(
      multiply(vec2(float(2.7), float(-4)), float(3.1)),
      vec2(float(2.8), float(4.4))
    )
  )
);

console.log(compileTypeScript("const result = ", expression));

console.log(compileJavascript("const result = ", expression));

console.log(compileGlsl("vec3 a = ", expression));

Outputs

TypeScript

const result = [
  testArgumentB - (testArgumentA[0] + (2.7 * 3.1 * 2.8 + -4 * 3.1 * 4.4)),
  testArgumentB - (testArgumentA[1] + (2.7 * 3.1 * 2.8 + -4 * 3.1 * 4.4)),
  testArgumentB - (testArgumentA[2] + (2.7 * 3.1 * 2.8 + -4 * 3.1 * 4.4)),
];

Javascript

const result = [
  testArgumentB - (testArgumentA[0] + (2.7 * 3.1 * 2.8 + -4 * 3.1 * 4.4)),
  testArgumentB - (testArgumentA[1] + (2.7 * 3.1 * 2.8 + -4 * 3.1 * 4.4)),
  testArgumentB - (testArgumentA[2] + (2.7 * 3.1 * 2.8 + -4 * 3.1 * 4.4)),
];

GLSL

vec3 a = testArgumentB - (testArgumentA + dot(vec2(2.7,-4.0) * 3.1, vec2(2.8,4.4)));

License

FOSSA Status