C header files in TypeScript

TypeScript implementations of 20 C standard library functions across 5 modules. Each function is individually importable and tree-shakeable.

ctype math stdio stdlib string

We have 20 C functions so far - help us add more

Got a rainy Sunday afternoon and a taste for a porting puzzle?

We will then review it. If it's useful to the project and in line with our contributing guidelines your work will become part of Locutus and you'll be automatically credited in the authors section accordingly.

Upstream Surface Inventory 20/83 shipped · 44 next 24%

Locutus tracks 5 upstream namespaces for C and sorts them into what is already shipped, what we still want, what we intentionally keep, and what still needs a decision.

24% catalog shipped
Shipped Next Explicit non-goals
ctype 57% stdlib 28% string 26% stdio 9% math 5%
Tracked namespaces 5
Shipped 20/83
Next to port 44
Explicit non-goals 19

stdlib.h

C23 · Catalog source: manual inventory https://en.cppreference.com/w/c/program

33% shipped
5/15 shipped 10 next 3 explicit non-goals
Shipped (5)

Next

Scalar conversion and numeric helpers are good portability targets.

  • atol
  • atoll
  • bsearch
  • labs
  • llabs
  • rand
  • strtof
  • strtoll
  • strtoul
  • strtoull
Explicit non-goals (3)
  • getenv Skip Process environment lookup depends on host state outside Locutus' model.
  • qsort Skip In-place comparator-driven sorting does not map cleanly to plain JS values.
  • srand Skip Global RNG seeding mutates ambient runtime state.

string.h

C23 · Catalog source: manual inventory https://en.cppreference.com/w/c/string/byte

50% shipped
5/10 shipped 5 next 9 explicit non-goals
Shipped (5)

Next

Character-class span helpers are useful for string scanning.

  • strcspn
  • strspn

Prefix-bounded string comparison still has a clean plain-value contract.

  • strncmp

Character-class search maps naturally to string scanning.

  • strpbrk

Last-occurrence search maps naturally to string lookup.

  • strrchr
Explicit non-goals (9)
  • memchr Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • memcmp Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • memcpy Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • memmove Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • memset Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strcpy Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strncat Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strncpy Skip C buffer and pointer-oriented string APIs do not generally map cleanly to JS plain values.
  • strtok Skip Stateful tokenizer semantics do not fit Locutus' plain-value model.

stdio.h

C23 · Catalog source: manual inventory https://en.cppreference.com/w/c/io

25% shipped
1/4 shipped 3 next 7 explicit non-goals
Shipped (1)

Next

Sized string formatting still produces a plain string result.

  • snprintf

Variadic string formatting still yields a plain string result.

  • vsnprintf
  • vsprintf
Explicit non-goals (7)
  • fprintf Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • fputs Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • printf Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • putchar Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • puts Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • vfprintf Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.
  • vprintf Skip stdio printing APIs are primarily output sinks rather than plain-value helpers.

math.h

C23 · Catalog source: manual inventory https://en.cppreference.com/w/c/numeric/math

5% shipped
1/21 shipped 20 next
Shipped (1)

Next

Scalar math helpers are strong plain-value portability targets.

  • acos
  • asin
  • atan
  • atan2
  • ceil
  • copysign
  • cos
  • exp
  • fabs
  • floor
  • fmod
  • hypot
  • log
  • log10
  • modf
  • pow
  • sin
  • sqrt
  • tan
  • trunc