MIT License

项目介绍

PHLAK/Twine 是一个托管在 GitHub 上的开源项目,主要使用 PHP 编写,采用 MIT License 许可证,目前获得 492 个 Star、23 次 Fork。

仓库全名
PHLAK/Twine
开源许可证
MIT License
Star 数
492
Fork 数
23
未关闭 Issue
1

README 摘要

String manipulation, leveled up! -- by, Chris Kankiewicz ( @phlak.dev ) Introduction Twine is a string manipulation library with an expressive, fluent syntax. Requirements PHP >= 8.1 The Multibyte String extension The OpenSSL extension Install with Composer Getting Started First, import Twine: Then instantiate a Twine object by newing up a Twine\Str object and passing your string as the first parameter. You may also…

完整内容见 GitHub 原始 README 或本页 。

常见问题

Twine 用什么语言开发?

主要使用 PHP 编写,采用 MIT License 许可证,目前有 492 个 Star。

Twine 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 Twine 的源码?

可以直接克隆仓库:git clone https://github.com/PHLAK/Twine.git,默认分支为 master;安装与运行步骤见仓库 README。

Twine 最近还在维护吗?

仓库最近一次更新为 5月4日,当前有 1 个未关闭 Issue;Star 数为 492,可作为社区活跃度的参考。

关于

String manipulation, leveled up!

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
551
价值分
303
活跃状态
活跃

语言占比

PHP

Release

README

Twine

String manipulation, leveled up! -- by, Chris Kankiewicz (@phlak.dev)

Join the Community Become a Sponsor One-time Donation
Latest Stable Version Total Downloads License Test Suite


Introduction

Twine is a string manipulation library with an expressive, fluent syntax.

Requirements

Install with Composer

composer require phlak/twine

Getting Started

First, import Twine:

use PHLAK\Twine;

Then instantiate a Twine object by newing up a Twine\Str object and passing your string as the first parameter.

$string = new Twine\Str('john pinkerton');

You may also instantiate a Twine\Str object statically via the make() method.

$string = Twine\Str::make('john pinkerton');

Or use the global str() helper method. The method takes a string as the only parameter and returns a Twine\Str object.

$string = str('john pinkerton');

Once you have a concrete Twine\Str instance you may treat it like any other string. This includes echoing it or using any of PHP’s built-in string functions against it.

echo $string; // Echos 'john pinkerton'

str_shuffle($string) // Returns something like 'enoipo ktnjhnr'

strlen($string); // Returns 14

The strength of Twine, however comes from its built-in methods.

$string->echo(); // Echos 'john pinkerton'
$string->shuffle(); // Returns something like 'enoipo ktnjhnr'
$string->length(); // Returns 14

// or some more interesting methods

$string->reverse(); // Returns 'notreknip nhoj'
$string->contains('pink'); // Returns true
$string->replace('pink', 'purple'); // Returns 'john purpleton'
$string->snakeCase(); // Returns 'john_pinkerton'

At this point you’re ready to start using Twine by calling any of its many built-in methods.

Available Methods

after • append • base64 • base64Decode • base64Encode • bcrypt • before • camelCase • characters • chunk • contains • count • crc32 • crypt • decrypt • echo • encoding • encrypt • endsWith • equals • explode • first • format • from • hex • hexEncode • hexDecode • insensitiveMatch • insert • in • isAlphabetic • isAlphanumeric • isEmpty • isLowercase • isNotEmpty • isNumeric • isPrintable • isPunctuation • isUppercase • isWhitespace • join • kebabCase • last • length • lowercase • lowercaseFirst • lowercaseWords • match • matchAll • matches • md5 • nth • pad • padBoth • padLeft • padRight • pascalCase • prepend • repeat • replace • reverse • sha1 • sha256 • shuffle • similarity • snakeCase • split • startsWith • strip • studlyCase • substring • to • trim • trimLeft • trimRight • truncate • uppercase • uppercaseFirst • uppercaseWords • url • words • wrap • wrapHard • wrapSoft


Method Chaining

A Twine string can be manipulated fluently by chaining methods. Here are a few example chains:

Perform a substring comparison:

$string = new Twine\Str('john pinkerton');

$string->substring(5, 4)->equals('pink'); // Returns true

Encode a file in compliance with RFC 2045.

$string = new Twine\Str(file_get_contents('garbage.bin'));

$string->base64()->wrap(76, "\r\n", Twine\Config\Wrap::HARD);

Additional details available in the full documentation at https://twine.phlak.net.

MultiByte Strings

Twine aims for multibyte string compatibility by relying on PHP’s Multibyte String extension (mbstring) to perform string operations. For this reason, the mbstring extension is required. Multibyte strings include Unicode encodings such as UTF-8 and UCS-2.

Changelog

A list of changes can be found on the GitHub Releases page.

Troubleshooting

For general help and support join our GitHub Discussion or reach out on Bluesky.

Please report bugs to the GitHub Issue Tracker.

This project is licensed under the MIT License.

评论

暂无评论