doughmii/dev-utils

A collection of small and useful PHP utilities for daily development

Installs: 8

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/doughmii/dev-utils

v1.0.2 2025-05-28 08:51 UTC

This package is auto-updated.

Last update: 2025-12-28 10:36:22 UTC


README

English | 简体中文

A lightweight PHP utility toolkit for daily development. Modular design — currently includes a Base62 encoder and a human-friendly time formatter, and more tools can be added over time.

Installation

Install via Composer:

composer require doughmii/dev-utils

Usage

🔢 Base62Encoder

A simple Base62 encoder/decoder that supports optional salt and batch encoding.

use DoughMii\DevUtils\Id\Base62Encoder;

$encoder = new Base62Encoder();

// Encode and decode a single integer
$encoded = $encoder->encode(123456);
$decoded = $encoder->decode($encoded);

// Encode and decode with salt
$encodedSalted = $encoder->encode(123456, 'my-salt');
$decodedSalted = $encoder->decode($encodedSalted, 'my-salt');

// Encode and decode multiple integers
$data = [1, 2, 3];
$encodedMultiple = $encoder->encodeMultiple($data, 'salt123');
$decodedMultiple = $encoder->decodeMultiple($encodedMultiple, count($data), 'salt123');

🕒 TimeHumanizer

Converts time differences into human-friendly text, supporting multiple languages (English, Chinese) and precise month/year logic.

use DoughMii\DevUtils\Time\TimeHumanizer;

$now = new DateTimeImmutable();
$past = $now->modify('-3 days');

echo TimeHumanizer::diffForHumans($past); // e.g. "3 days ago"
echo TimeHumanizer::fromNow($past);       // same as above

// With custom locale (zh)
echo TimeHumanizer::diffForHumans($past, null, 'zh'); // "3 天前"

测试

运行 PHPUnit 测试:

vendor/bin/phpunit

许可证

MIT