Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→email-all-chars-within-asciinext

email-all-chars-within-ascii5.2.1

Scans all characters within a string and checks are they within ASCII range

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • IDEA
  • API — WITHIN()
  • API — DEFAULTS
  • API — VERSION
  • API — TYPES
  • Changelog

Installation

Quick Take

Examples

  • Tabs and line breaks are allowed
  • Set a custom maximum line length
  • Disable the line length check
  • Report every non-ASCII character found

Idea

Traverse the string and check if all characters are suitable for 7bit encoding, in other words, are within the basic ASCII range, first 126 characters, and does not include any invisible control characters.

We don’t want any invisible control characters (anything below decimal point 32), EXCEPT:

  • HT, horizontal tab, decimal number 9
  • LF, new line, decimal number 10
  • CR, carriage return, decimal number 13

Often decimal point 127, DEL, is overlooked, yet it is not right in your templates, especially email.

In that sense, non-ascii regexopens in a new tab and the likes are dangerous to validate your email template code because they are too lax.

Also, we want an error reported if any lines exceed the recommended line length in email, 500 characters-per-line.

API — within()

The main function within() is imported like this:

It’s a function which takes two input arguments:

The optional options object has the following shape:

KeyTypeObligatoryDefaultDescription
lineLength
Type: number
Obligatory: no
Default: 500
lineLengthnumberno500Max line length allowed. Set to 0 to disable.

Here are all defaults in one place for copying:

API — defaults

You can import defaults:

It's a plain object:

The main function calculates the options to be used by merging the options you passed with these defaults.

API — version

You can import version:

API — types

This package is written in TypeScript and exports the following types:

TypeDescription
Opts
Type: Opts
OptsThe Optional Options Object of within(), documented above.
Res
Type: Res
ResOne reported finding — its type, line, column, positionIdx, value and, for characters, codePoint and UTF32Hex. within() returns an array of these.
import type { Opts, Res } from "email-all-chars-within-ascii";

Changelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab