dragon-code / size-sorter
Easily sort clothing size, height, bra size, furniture size and more
Fund package maintenance!
Boosty
Yoomoney
Donationalerts
Installs: 10 176
Dependents: 1
Suggesters: 0
Security: 0
Stars: 31
Watchers: 2
Forks: 1
Open Issues: 1
Requires
- php: ^8.1
- archtechx/enums: ^0.3.1
- dragon-code/support: ^6.9
- illuminate/collections: ^8.75 || ^9.0 || ^10.0 || ^11.0
Requires (Dev)
- fakerphp/faker: ^1.21
- illuminate/database: ^8.75 || ^9.0 || ^10.0 || ^11.0
- phpunit/phpunit: ^9.6
- symfony/var-dumper: ^5.3 || ^6.0 || ^7.0
README
Easily sort clothing size, height, bra size, furniture size and more
Installation
To get the latest version of Product Size Sorter
, simply require the project using Composer:
composer require dragon-code/size-sorter
Or manually update require
block of composer.json
and run composer update.
{ "require": { "dragon-code/size-sorter": "^1.0" } }
Compatibility
Note
This package can work outside the frameworks systems.
Usage
When calling a sort with common values, each element will be assigned to one of five groups:
- Letter clothing size (XXS, XS, M, L, etc.)
- Numerical size of clothes and shoes (9, 10, 44-46, 48, etc.)
- Bra size (70B, 75A, 80C, etc...)
- Overall dimensions of items (40x38x19 sm, etc.)
- Other values
use DragonCode\SizeSorter\Sorter; return Sorter::sort(collect([ 'XXL', '26', '28', 'XL', 'ONE SIZE', 'XXS', '2', '54', ])); /* * Returns: * * Collection([ * 'XXS', * 'XL', * 'XXL', * '2', * '26', * '28', * '54', * 'ONE SIZE', * ]) */
use DragonCode\SizeSorter\Sorter; $items = Size::query()->get(); return Sorter::sort($items, 'title');
You can see more examples in the test file.
Groups Order
By default, sizes are sorted by the following logical blocks:
- Letter clothing size (XXS, XS, M, L, etc.)
- Numerical size of clothes and shoes (9, 10, 44-46, 48, etc.)
- Bra size (70B, 75A, 80C, etc...)
- Overall dimensions of items (40x38x19 sm, etc.)
- Other values
But you can change the order by specifying identifiers as the third parameter:
use DragonCode\SizeSorter\Enum\Group; use DragonCode\SizeSorter\Sorter; return Sorter::sort($items, groupsOrder: [3, 5, 4, 2, 1]); // or return Sorter::sort($items, groupsOrder: [Group::GROUP_3, Group::GROUP_5, Group::GROUP_4, Group::GROUP_2, Group::GROUP_1]);
The final array will be formed in the specified order:
3 - 5 - 4 - 2 - 1
You can also specify some groups. For example:
use DragonCode\SizeSorter\Enum\Group; use DragonCode\SizeSorter\Sorter; return Sorter::sort($items, groupsOrder: [3, 5]); // or return Sorter::sort($items, groupsOrder: [Group::GROUP_3, Group::GROUP_5]);
In this case, the first two logical groups will be sorted in the specified order, and the subsequent ones will be in ascending order:
3 - 5 - 1 - 2 - 4
License
This package is licensed under the MIT License.