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 🙏

© 2024 – Pkg Stats / Ryan Hefner

friendly-name-parser

v1.0.1

Published

A module that allows for the normalization of usernames and validation to detect HTML, JS, or PHP code.

Downloads

11

Readme

✨ Friendly Name Parser

friendly-name-parser is a library for Node.js that assists in processing user names into easily readable strings. The goal of this library is to enhance the readability and security of input data in web applications.

✔️ Main features

  • Parsing usernames: Converts usernames into a format that is easier to read and process in systems.
  • Input data validation: Checks if the user-input data contains undesirable content, such as HTML, JavaScript (JS), or PHP code, preventing potential code injection attacks.
  • Handling break spaces: Ensures that usernames do not contain unexpected breaks (e.g., through additional spaces), which is crucial for maintaining data consistency.
  • Validation and normalization of spaces: The module identifies and normalizes excessive and unusual spaces, ensuring uniformity of input data formatting.
  • Detection and cleaning of code: The library has the ability to recognize and eliminate HTML, JavaScript, and PHP code from the passed strings, preventing potential XSS attacks and other forms of code injection.
  • Recognition and filtering of URLs and email addresses: The library can detect and remove URLs and process email addresses from the text.
  • Validation of string structure and content: Advanced regular expressions are used to detect improper characters, excessive use of periods, and inappropriate use of spaces before punctuation marks, thereby ensuring grammatical and stylistic correctness of the data.
  • Ensuring readability and aesthetics of output data: Through transformations such as capitalizing appropriate words and removing unnecessary spaces, the library facilitates the creation of text that is not only safe but also aesthetically pleasing.

📝 Additional notes

  • Synchronicity: The library operates synchronously. It does not, for example, affect the server-side query execution time.
  • No dependencies: The module does not require the installation of additional dependencies, facilitating its integration with existing projects.
  • Support for Node.js and browsers: The library is compatible with Node.js and web browsers, allowing its versatile use in various environments.

🦈 Applications

The FriendlyNameParser module was designed to enhance the account registration processes in web applications. It enables the processing and normalization of input data, which increases the security and readability of information provided by users.

📥 Installation

Node.js

To install this module in a Node environment, use the following npm command:

npm install friendly-name-parser

🌍 Browser

If you want to use this module in a browser, you can use the following HTML code:

<script src="https://cdn.jsdelivr.net/npm/friendly-name-parser@1/dist/friendly-name-parser.min.js"></script>

🐱 Examples

Username normalization

const FriendlyNameParser = require('friendly-name-parser');

const myUsername = 'I LOVE CUTE cats!!! 💞😻';
const data = FriendlyNameParser(myUsername);
console.log(data.pretty); // "I Love Cute Cats"

Condensed version with more normalization examples (data.pretty)

'<h1>Hello World</h1>'; // "Hello World"
'<script>alert("Hello World")</script>'; // "Hello World"
'😺🔢🤔neko🕵️‍♀️🔥😸📷⚠'; // "Neko"
'[email protected]'; // "Sefinek"
'  Hello   World  '; // "Hello World"
'Hello... World'; // "Hello World"
'Goodbye world 😥🌍👋'; // "Goodbye World"

Full returned object (Regular username)

const FriendlyNameParser = require('friendly-name-parser');

const myUsername = '😻I !!LOVE!! CaTs 💞';
const data = FriendlyNameParser(myUsername);
console.log(data);

// Output:
// {
//     input: '😻I !!LOVE!! CaTs 💞',
//     pretty: 'I Love Cats',
//     isHTML: false,
//     isJS: false,
//     isPHP: false,
//     breakSpaces: false,
//     hasMultilineComments: false,
//     isPlainText: true,
//     detected: []
// }

Full returned object (Username with break spaces and JS code)

const FriendlyNameParser = require('friendly-name-parser');

const myUsername = '<script>alert("l itt le gat ito");</script>';
const data = FriendlyNameParser(myUsername);
console.log(data);

// Output:
// {
//     input: '<script>alert("l itt le gat ito");</script>',
//     pretty: 'Little Gatito',
//     isHTML: true,
//     isJS: true,
//     isPHP: false,
//     breakSpaces: true,
//     hasMultilineComments: false,
//     isPlainText: false,
//     detected: [ 'HTML', 'JS', 'Break spaces' ]
// }

Other Examples

You can find a larger collection of examples in the examples folder.

🤝 Support

If you encounter any issues or have questions regarding the use of friendly-name-parser, please submit an Issue in the GitHub repository.

📑 License

The module is available under the MIT license. Details can be found in the LICENSE file in the root directory of the repository.