1.0.9 • Published 10 months ago

@imhonglu/format v1.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

@imhonglu/format

English | 한국어

Introduction

  • A strongly-typed string formatting library that complies with RFC standards
  • Provides an interface similar to the native JSON API
  • All Formatters consistently provide parse, stringify, and safeParse methods
  • Parsed objects are automatically serialized to strings when using JSON.stringify()

Table of Contents

Installation

npm install @imhonglu/format

Usage

For detailed examples, please refer to the API Reference.

import { FullTime } from '@imhonglu/format';
// Parse time string
const time = FullTime.parse('00:00:00.000Z');
// { hour: 0, minute: 0, second: 0, secfrac: '.000', offset: undefined }

// Using parsed results
console.log(time.hour); // 0
console.log(time.toString()); // '00:00:00.000Z'
console.log(JSON.stringify(time)); // '"00:00:00.000Z"'

// Safe parsing with validation
const result = FullTime.safeParse('invalid');
if (result.ok) {
  console.log(result.data);
  // result.data returns parsed FullTime instance
} else {
  console.error(result.error);
  // result.error returns InvalidFullTimeError with error information
}

API Reference

Date Time Formatter(RFC 3339)

IP Address Formatter(RFC 2673, RFC 4291, RFC 5954)

Hostname Formatter(RFC 1034, RFC 5890)

Email Formatter(RFC 5321, RFC 5322)

URI Formatter(RFC 3986, RFC 3987)

APIs that support IRI commonly provide the { isIri: boolean } option.

  • URI - URI / IRI based on RFC 3986, RFC 3987
  • URIReference - URI Reference / IRI Reference based on RFC 3986, RFC 3987
  • Authority - Authority / IRI Authority based on RFC 3986, RFC 3987
  • Path - Path / IRI Path based on RFC 3986, RFC 3987
  • Query - Query / IRI Query based on RFC 3986, RFC 3987
  • Fragment - Fragment / IRI Fragment based on RFC 3986, RFC 3987
  • Scheme - Scheme based on RFC 3986
  • IPvFuture - IPvFuture based on RFC 3986

URI Template Formatter(RFC 6570)

UUID Formatter(RFC 4122)

  • UUID - UUID based on RFC 4122

JSON Pointer Formatter(RFC 6901)

1.0.9

10 months ago

1.0.8

11 months ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago