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 🙏

© 2026 – Pkg Stats / Ryan Hefner

nv-constexpr-simple-codify

v1.0.7

Published

A slow but precise object-to-code converter designed specifically for **macro compilation tools** and compile-time code generation.

Readme

nv-constexpr-simple-codify

A slow but precise object-to-code converter designed specifically for macro compilation tools and compile-time code generation.

Its a readable But less-suportted-type version of nv-buf-data-to-code.

⚠️ Important Notice

This library is NOT optimized for performance. It is intentionally slow because it generates executable JavaScript code rather than serialized data. Use it only when you need:

  • Compile-time constant evaluation
  • Macro expansion systems
  • Generating code from configuration objects
  • Static analysis tools that output executable code

Do NOT use this for runtime serialization or high-frequency operations.

Supported Leaf Types (1:1 C++ Mapping)

Every supported leaf type has a direct 1:1 counterpart in C++. This makes the output ideal for generating C++ constexpr-compatible code.

| JavaScript Type | C++ Equivalent | Output Format | Example | |-----------------|----------------|---------------|---------| | undefined | Special NaN sentinel | undefined | undefined (see note below) | | null | std::nullptr_t / NULL | null | null | | boolean | bool | true / false | true | | string | std::string / const char* | JSON-stringified | "hello\nworld" | | number | double / float / int | String representation | 123.45 | | bigint | std::int64_t / std::uint64_t | n suffix notation | 9007199254740993n | | ArrayBuffer | std::array<uint8_t> (raw buffer) | IIFE with byte array | (()=>{ var ab = new ArrayBuffer(8);(new Uint8Array(ab)).set([0,32,64,96,128,160,192,224]);return(ab);})() | | SharedArrayBuffer | std::shared_ptr<std::array<uint8_t>> | IIFE with byte array | Same format as ArrayBuffer | | DataView | struct with manual byte access | new DataView(...) | (new DataView((new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])).buffer)) | | Uint8Array | std::array<uint8_t> | new Uint8Array([...]) | (new Uint8Array([1,2,255])) | | Uint8ClampedArray | std::array<uint8_t> (clamped) | new Uint8ClampedArray([...]) | (new Uint8ClampedArray([0,128,255])) | | Int8Array | std::array<int8_t> | new Int8Array([...]) | (new Int8Array([-128,0,127])) | | Uint16Array | std::array<uint16_t> | new Uint16Array([...]) | (new Uint16Array([1,65535])) | | Int16Array | std::array<int16_t> | new Int16Array([...]) | (new Int16Array([-32768,32767])) | | Uint32Array | std::array<uint32_t> | new Uint32Array([...]) | (new Uint32Array([1,4294967295])) | | Int32Array | std::array<int32_t> | new Int32Array([...]) | (new Int32Array([-2147483648,2147483647])) | | Float32Array | std::array<float> | new Float32Array([...]) | (new Float32Array([1.5,-2.5,0])) | | Float64Array | std::array<double> | new Float64Array([...]) | (new Float64Array([1.7976931348623157e+308,-Infinity,NaN])) | | BigUint64Array | std::array<uint64_t> | new BigUint64Array([...]) | (new BigUint64Array([18446744073709551615n])) | | BigInt64Array | std::array<int64_t> | new BigInt64Array([...]) | (new BigInt64Array([-9223372036854775808n])) | | Date | std::chrono::system_clock::time_point | new Date(timestamp) | (new Date(1705321845123)) | | RegExp | do NOT use std::regex | /pattern/flags | /test\/pattern/gi |

Special Note on undefined

undefined does not have a direct C++ equivalent. In C++ code generation scenarios, it should be replaced with a special NaN sentinel value (nan is a range)) or a designated invalid marker. The codifier outputs undefined` as-is for transparency, leaving the C++ mapping decision to the downstream compiler logic.

BigInt Note on Large BigInt: For values exceeding 64 bits, GCC's __int128can be used. For arbitrarily large values beyond __int128range, consider directly copying V8's bigint.ccimplementation into your project.

RegExp use a third-party library that supports compile-time regex (do NOT use std::regex)

String

new String (typeof !== string BUT instanceof String) ; this is for special use: to generate var-name/identifier ; will NOT be quoted. string will be JSON.stringify(quoted)

Container Support

Only two container types are supported:

  1. Arrays [] - Indexed collections
  2. Plain Objects {} - String-keyed collections

Nested structures are fully supported (arrays within objects, objects within arrays, etc.).

Unsupported containers:

  • Map - Not supported
  • Set - Not supported
  • WeakMap - Not supported
  • WeakSet - Not supported
  • Array-like objects - Not supported
  • Custom classes/constructors - Not supported

API

codify(obj, space = 0)

Main entry point. Converts an object to a code string.

  • obj - The object to convert (must contain only supported types)
  • space - Optional indentation:
    • 0 or "" (empty string) - No indentation, compact output
    • number - Number of spaces per level
    • string - Custom indentation string

Returns: string - Executable JavaScript code

Internal Functions

For advanced use cases, the following internal functions are exported:

  • _codify_leaf(o) - Convert a single leaf value
  • _codify_ary(ary, depth, space, recv, is_lst, key) - Process arrays
  • _codify_dict(dict, depth, space, recv, is_lst, key) - Process objects
  • _codify_typed_ary(o, Cls) - Convert TypedArrays/DataView
  • _codify_ab(o, ClsName) - Convert ArrayBuffer/SharedArrayBuffer

Use Cases

This tool is designed for:

  1. Macro Compilation Systems - Generate code at compile time
  2. Static Configuration - Convert config objects to constants
  3. Code Generation Tools - Build source code from templates
  4. Build-time Optimizations - Pre-compute values during build
  5. Domain-Specific Languages - Implement DSL compilers

Performance Note

This library prioritizes code fidelity over execution speed. It is significantly slower than JSON.stringify because:

  • It generates executable code, not just data
  • It handles many more data types
  • It performs recursive processing with string building
  • It's not optimized for large datasets

Do NOT use it For runtime serialization.

License

Any