Giter Club home page Giter Club logo

laravel-advanced-string's Introduction

Laravel Advanced String Package

Tested, community maintained, supercharged Laravel string functions.

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Laravel Advanced String is a Laravel package that adds advanced string manipulation methods to the built in Str class that Laravel provides. You get extended functionality on strings such as advanced password generation, data redaction, and more.

The Laravel Advanced String package by default adds macros to the Str class so your can access the extended functionality in the same class that your other string methods are found in. You can also disable this functionality the in the package config and use the AdvStr class directly.

Example

ssnRedaction-compressed.mp4
Str::redactSsn('My social security number is 222-22-2222'); // My social security number is xxxxxx

OR...

AdvStr::redactSsn('My social security number is 222-22-2222'); // My social security number is xxxxxx

Table of Contents

Installation

You can install the package via composer:

composer require mpstenson/laravel-advanced-string

You can publish the config file with:

php artisan vendor:publish --tag="laravel-advanced-string-config"

This is the contents of the published config file:

return [

    /*
    // Macro the AdvStr class to the Illuminate\Support\Str class. You can disable
    // this here if you don't want the AdvStr methods available on the Str class
    */

    'use_str' => true,

];

Usage

The Laravel Advanced String package by default adds macros to the Str class so your can access the extended functionality immediately

Str::redactSsn('123-45-6789')

Available Methods

Generates a random, secure password.

public static function advPassword(
    $length = 32,
    $letters = true,
    $numbers = true,
    $symbols = true,
    $spaces = false,
    $upperLetters = false,
    $lowerLetters = false,
    $exclude = []
)

Parameters:

  • $length (int): Length of the password (default: 32)
  • $letters (bool): Include mixed case letters (default: true)
  • $numbers (bool): Include numbers (default: true)
  • $symbols (bool): Include symbols (default: true)
  • $spaces (bool): Include spaces (default: false)
  • $upperLetters (bool): Include uppercase letters (default: false)
  • $lowerLetters (bool): Include lowercase letters (default: false)
  • $exclude (array): Characters to exclude from the password

Returns:

  • string: Generated password

Wraps a string at a given number of characters regardless of words.

public static function charWrap(
    $string, 
    $length = 80
)

Parameters:

  • $string (string): The string to wrap
  • $length (int): The number of characters to wrap at (default: 80)

Returns:

  • string: The wrapped string

Extracts the domain part of an email address, including subdomains.

public static function emailDomain(
    $string
)

Parameters:

  • $string (string): The string to extract the email domain from.

Returns:

  • string: The email domain from the string

Calculates the read time of a string.

public static function readTime(
    $string, 
    $wpm = 200
)

Parameters:

  • $string (string): The text to calculate read time for
  • $wpm (int): Words per minute (default: 200)

Returns:

  • float: Estimated read time in seconds

Redacts credit card numbers in a string.

public static function redactCreditCard(
    $string, 
    $redacted = '********', 
    $exclude = []
)

Parameters:

  • $string (string): The string containing credit card numbers to redact
  • $redacted (string): The string to replace credit card numbers with (default: '********')
  • $exclude (array): An array of credit card types to exclude from redaction. Possible types: 'mastercard','visa','amex','discover','diners','jcb'

Returns:

  • string: The string with credit card numbers redacted

Redacts Social Security Numbers (SSN) in a string.

public static function redactSsn(
    $string, 
    $redacted = '********', 
    $dashes = true, 
    $noDashes = true
)

Parameters:

  • $string (string): The string containing SSNs to redact
  • $redacted (string): The string to replace SSNs with (default: '********')
  • $dashes (bool): Redact SSNs with dashes (default: true)
  • $noDashes (bool): Redact SSNs without dashes (default: true)

Returns:

  • string: The string with SSNs redacted

Splits a full name into first name, middle name (if present), and last name, removing any prefixes and suffixes. This method can handle both "Firstname Lastname" and "Lastname, Firstname" formats.

public static function splitName(
    $name
)

Parameters:

  • $name (string): The full name to split

Returns:

  • array: An associative array containing 'first', 'middle' (if present), and 'last' name

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

laravel-advanced-string's People

Contributors

mpstenson avatar matthewpaulking avatar dependabot[bot] avatar github-actions[bot] avatar

Stargazers

Ryan Taylor avatar jadesoriano avatar Yoss FazWaz avatar Shanaka Madusanka avatar Aleksandar Mitic avatar Alec Garcia avatar Renato Soares avatar UchMan avatar Ifeanyi Nnaemego avatar Optimliner avatar Dung Phan avatar Eugene Musienko avatar hiro avatar  avatar 薄荷蓝的晴天 avatar Irfaq Syed avatar  avatar Tyler Trushin avatar Ihor Vorotnov avatar Can Yılmaz avatar  avatar Tom Sacré avatar Ibrahim Lasisi avatar Abdul Basit Rana avatar guanguans avatar Alexander Hofbauer avatar  avatar Albert Clo avatar Gary Blankenship avatar Mark Stralka avatar Alfred Nutile avatar Ian Hawes avatar Mohammad Prince avatar Mehmet Akif TEZCAN avatar Tuan avatar Abdelhamid Errahmouni avatar Ahti Nurme avatar Lloric Mayuga Garcia avatar David Harting avatar Ibnu Hajar avatar Raphael Botelho avatar  avatar Hassan Ibrahim avatar Abdulsalam alblihi avatar Bagaskara Wisnu Gunawan avatar Daniel Šádek avatar Diaa Fares avatar Cyril Fehintoluwa avatar Ricardo Sawir avatar Daniel Hartmann avatar Nathan Rzepecki avatar Adeniji Charles Ayodipupo avatar Sajjad Hossain Shohag avatar  avatar Jorge Enríquez avatar Mustafa TOKER avatar Max Orlov avatar Ben Holmen avatar Andrew Rhyand avatar Ian Landsman avatar  avatar

Watchers

 avatar  avatar Optimliner avatar

laravel-advanced-string's Issues

[Bug]: No publishable resources for tag [laravel-advanced-string-config]

What happened?

I run php artisan vendor:publish --tag="laravel-advanced-string-config", as per the documentation steps, but I've got an INFO message: "No publishable resources for tag [laravel-advanced-string-config]" and no config file is present.

How to reproduce the bug

I've just followed the installation steps:

  • mpstenson/laravel-advanced-string package
  • I run php artisan vendor:publish --tag="laravel-advanced-string-config", but I've got an INFO message: "No publishable resources for tag [laravel-advanced-string-config]" and no config file is present

Package Version

1.0.0

PHP Version

8.3

Laravel Version

11.18.1

Which operating systems does with happen with?

Windows

Notes

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.