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

strfname-ts

v0.1.1

Published

A TypeScript library to format names.

Downloads

1

Readme

strfname-ts

A simple, intuitive TypeScript library for formatting personal names using format strings, based on the NFN (Name Format Notation) standard.

Installation

npm install strfname-ts
# or
yarn add strfname-ts
# or
pnpm add strfname-ts

Usage

Import the formatName function and pass it an options object containing the name and an optional format string.

import { formatName, Name, setDefaultFormat } from 'strfname-ts';

const name: Name = {
  firstName: 'Ada',
  middleName: 'King',
  lastName: 'Lovelace',
};

// Format a name using a specific format string
console.log(formatName({ name, format: 'F L' }));   // "Ada Lovelace"
console.log(formatName({ name, format: 'L, F' }));   // "Lovelace, Ada"
console.log(formatName({ name, format: 'F J. L' })); // "Ada K. Lovelace"

// Missing parts are handled gracefully
const simpleName: Name = {
  firstName: 'Jane',
  lastName: 'Smith',
};
console.log(formatName({ name: simpleName, format: 'L, F M' })); // "Smith, Jane"

// You can also set a global default format
setDefaultFormat('L, F');

console.log(formatName({ name })); // "Lovelace, Ada"

NFN Format Codes

| Code | Description | Example (for Ada King Lovelace) | | :---- | :---- | :---- | | F | First Name (Title Case) | Ada | | f | first name (lowercase) | ada | | L | Last Name (Title Case) | Lovelace | | l | last name (lowercase) | lovelace | | M | Middle Name (Title Case) | King | | m | middle name (lowercase) | king | | I | First Initial (Uppercase) | A | | i | first initial (lowercase) | a | | J | Middle Initial (Uppercase) | K | | j | middle initial (lowercase) | k | | K | Last Initial (Uppercase) | L | | k | last initial (lowercase) | l |

NFN Examples

Western Names

By combining the codes, you can construct any desired format.

Given Name: Ada King Lovelace

| Format String | Resulting Output | | :---- | :---- | | F L | Ada Lovelace | | L, F | Lovelace, Ada | | L, F M | Lovelace, Ada King | | F J. L | Ada K. Lovelace | | I.J.K. | A.K.L. |

International Usage

NFN is flexible enough to handle various global naming conventions by storing the appropriate parts of the name in the firstName and lastName fields.

| Convention | Example Name Data | Format String | Resulting Output | | :---- | :---- | :---- | :---- | | Chinese (Family Name First) | firstName: "Míng", lastName: "Yáo" | L F | Yáo Míng | | Hungarian (Family Name First) | firstName: "Viktor", lastName: "Orbán" | L F | Orbán Viktor | | Spanish (Compound Surname) | firstName: "Gabriel", lastName: "García Márquez" | F L | Gabriel García Márquez | | Icelandic (Patronymic) | firstName: "Björk", lastName: "Guðmundsdóttir" | F L | Björk Guðmundsdóttir | | Arabic (Patronymic) | firstName: "Mohammed", lastName: "bin Salman" | F L | Mohammed bin Salman |

License

This library is licensed under the MIT License. The NFN specification itself is free to use and adapt.