Registry / devops / glsl-token-whitespace-trim

glsl-token-whitespace-trim

JSON →
library1.0.0jsnpmunverified

Trims whitespace in an array of GLSL tokens from glsl-tokenizer, used to minimize shader source size. Version 1.0.0 stable. Accepts optional boolean to remove all extraneous whitespace. Part of stackgl ecosystem. No active development since 2016.

npm install glsl-token-whitespace-trim
INSTALL
IMPORT
SIG · GLSL-TOKEN-WHITESP
G
glsl-token-whitespace-trim
devopsjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

trim
import trim from 'glsl-token-whitespace-trim'
const { trim } = require('glsl-token-whitespace-trim')
Package exports a single default function; named import or CJS require works but default is standard.
trim (CommonJS)
const trim = require('glsl-token-whitespace-trim')
CJS require works fine; package is not ESM-only.
TypeScript types
import trim from 'glsl-token-whitespace-trim'
import { default as trim } from 'glsl-token-whitespace-trim'
No official TypeScript types; if using @types/glsl-token-whitespace-trim (unlikely), default import is fine.

Tokenizes GLSL source, trims all whitespace, and reconstructs string.

import tokenize from 'glsl-tokenizer'; import string from 'glsl-token-string'; import trim from 'glsl-token-whitespace-trim'; const src = ` precision mediump float; void main() { gl_FragColor = vec4(1.0); } `; const tokens = tokenize(src); trim(tokens, true); const result = string(tokens); console.log(result); // Output: 'precision mediump float;void main(){gl_FragColor=vec4(1.0);}'
Debug
Known issues
gotchaSecond argument `all` must be boolean; passing undefined or false triggers default behavior (keep at most two newlines).
fix
Always pass true or false explicitly: trim(tokens, true) or trim(tokens, false).
affects: >=1.0.0
gotchaPackage mutates the tokens array in-place; does not return a new array.
fix
Be aware the input tokens array is modified; clone beforehand if needed.
affects: >=1.0.0
gotchaExpects tokens generated by glsl-tokenizer specifically; tokens from other tokenizers may not have correct structure.
fix
Ensure tokens are from glsl-tokenizer (token.type, token.data, token.position, etc.).
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: tokens is not iterable
Passed a non-array to trim()
fix
Ensure trim() receives an array of token objects.
Cannot read property 'type' of undefined
Tokens array contains undefined or malformed tokens
fix
Verify each token is an object with expected properties.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
10
Resources
glsl-token-whitespace-trim — npm install glsl-token-whitespace-trim · libregistry