{"id":41156,"library":"glsl-token-whitespace-trim","title":"glsl-token-whitespace-trim","description":"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.","status":"maintenance","version":"1.0.0","language":"javascript","source_language":"en","source_url":"git://github.com/hughsk/glsl-token-whitespace-trim","tags":["javascript","glsl","token","tokenizer","glslify","ecosystem:stackgl","whitespace","trim"],"install":[{"cmd":"npm install glsl-token-whitespace-trim","lang":"bash","label":"npm"},{"cmd":"yarn add glsl-token-whitespace-trim","lang":"bash","label":"yarn"},{"cmd":"pnpm add glsl-token-whitespace-trim","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package exports a single default function; named import or CJS require works but default is standard.","wrong":"const { trim } = require('glsl-token-whitespace-trim')","symbol":"trim","correct":"import trim from 'glsl-token-whitespace-trim'"},{"note":"CJS require works fine; package is not ESM-only.","symbol":"trim (CommonJS)","correct":"const trim = require('glsl-token-whitespace-trim')"},{"note":"No official TypeScript types; if using @types/glsl-token-whitespace-trim (unlikely), default import is fine.","wrong":"import { default as trim } from 'glsl-token-whitespace-trim'","symbol":"TypeScript types","correct":"import trim from 'glsl-token-whitespace-trim'"}],"quickstart":{"code":"import tokenize from 'glsl-tokenizer';\nimport string from 'glsl-token-string';\nimport trim from 'glsl-token-whitespace-trim';\n\nconst src = `\nprecision mediump float;\n\nvoid main() {\n    gl_FragColor = vec4(1.0);\n}\n`;\nconst tokens = tokenize(src);\ntrim(tokens, true);\nconst result = string(tokens);\nconsole.log(result);\n// Output: 'precision mediump float;void main(){gl_FragColor=vec4(1.0);}'","lang":"javascript","description":"Tokenizes GLSL source, trims all whitespace, and reconstructs string."},"warnings":[{"fix":"Always pass true or false explicitly: trim(tokens, true) or trim(tokens, false).","message":"Second argument `all` must be boolean; passing undefined or false triggers default behavior (keep at most two newlines).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Be aware the input tokens array is modified; clone beforehand if needed.","message":"Package mutates the tokens array in-place; does not return a new array.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure tokens are from glsl-tokenizer (token.type, token.data, token.position, etc.).","message":"Expects tokens generated by glsl-tokenizer specifically; tokens from other tokenizers may not have correct structure.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.0':25 '2016':43 'accept':27 'activ':40 'array':10 'boolean':29 'develop':41 'ecosystem':38,49 'extran':33 'glsl':2,12,16,45 'glsl-token':15 'glsl-token-whitespace-trim':1 'glslifi':48 'javascript':44 'minim':20 'option':28 'part':35 'remov':31 'shader':21 'sinc':42 'size':23 'sourc':22 'stabl':26 'stackgl':37,50 'token':3,13,17,46,47 'trim':5,6,52 'use':18 'version':24 'whitespac':4,7,34,51","created_at":"2026-06-04T18:51:02.883328+00:00","updated_at":"2026-06-04T18:51:02.883328+00:00","problems":[{"fix":"Ensure trim() receives an array of token objects.","cause":"Passed a non-array to trim()","error":"TypeError: tokens is not iterable"},{"fix":"Verify each token is an object with expected properties.","cause":"Tokens array contains undefined or malformed tokens","error":"Cannot read property 'type' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/hughsk/glsl-token-whitespace-trim","github":"git://github.com/hughsk/glsl-token-whitespace-trim","docs":null,"changelog":null,"pypi":null,"npm":"glsl-token-whitespace-trim","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}