ascetik/primalvalues

处理原始类型的简单类

v0.1.0 2024-01-20 10:29 UTC

This package is auto-updated.

Last update: 2024-09-20 16:12:31 UTC


README

一些处理原始类型的类

发行说明

v.O.1.0 : 草稿

  • PrimalValue 接口 - 仍然不完整
  • PrimalString 实现 - 现在字符串可以有自己的方法...
  • Numerik 实现 - 带有方法的数值。

PrimalString

处理字符串的对象化方法。

PrimalString 的构造函数是私有的。要实例化一个 PrimalString,请使用 ofempty 静态方法之一。

方法和描述

  • charAt(int $index): self 返回一个新实例,其中包含当前值在给定索引处的字母。在负 $index 时,从当前值的末尾开始搜索。如果 $index 大于值的长度,则返回空实例。

  • concat(string|self $sequence): self 返回一个新实例,其中指定的字符串附加到当前字符串。

  • contains(string/self $sequence): bool 检查当前值是否包含给定的序列。

  • endsWith(string/self $sequence): bool 检查当前值是否以给定的序列结束。

  • equals(mixed $string): bool 检查给定 PrimalString 的值相等性,否则为严格相等。

  • indexOf(string/self $sequence): int 返回该值的序列的索引,如果未找到则返回 -1。

  • isEmpty(): bool 检查当前值是否为空。

  • lastIndexOf(string/self $sequence): int 返回最后找到的序列的索引,如果未找到则返回 -1。

  • length(): int 返回当前值的长度。

  • matches(string $regex): bool 使用正则表达式检查当前值的格式。

  • replace(string|self|array $oldVal, string|self|array $newVal): self 返回一个新实例,其中替换了序列。

  • replaceAll(string|array $regex, string|self|array $replacement): self 将与给定表达式匹配的所有序列从当前值替换为替换内容。

  • split(string $regex): array 返回使用给定的正则表达式模式拆分当前值的字符串序列数组。

  • startsWith(string/self $sequence): bool 检查当前值是否以给定的序列开头。

  • subString(int $offset, ?int $length): self 返回一个新实例,从当前值开始于 $offset,如果给定,则包含 $length 个字符,否则直到末尾,如果发生错误,则返回空实例。

  • toArray(): array 返回当前值中每个字符的实例数组。

  • toLowerCase(): self 返回一个新的实例,其当前值已转换为小写。

  • toUpperCase(): self 返回一个新的实例,其当前值已转换为大写。

  • trim(string|self|null $chars): self 返回一个新的实例,从当前值中删除尾随空格和 $chars 在开始和结束处。

  • 静态 of(string $sequence): self 返回一个新实例,包含给定的序列。

  • 静态 empty(): self 返回一个新的空实例。

Numerik

处理数值的对象化方式。在这个版本中,整数和浮点值之间没有区别。

私有构造函数。使用 ofzero 静态方法构建 Numerik 实例。

方法和描述

  • add(int|float|self $number): self 返回一个新实例,其当前值与给定值之和。

  • cube(): self 返回当前值的三次幂的self实例。

  • decrement(int|float|self $decrease = 1): self 返回一个新实例,其当前值减去给定值。

  • divides(int|float|self $dividend): self 返回一个新实例,其值为给定数除以self值。如果当前值等于0,则返回零实例。

  • dividedBy(int|float|self $divider): self 返回一个新实例,其值为self值除以给定数。如果$number等于0,则返回零实例。

  • equals(): bool 检查当前实例与给定值之间的严格相等性。

  • exposing(int|float|self $number): self 返回给定数的self实例,其值为当前值的幂。

  • increment(int|float|self $increase = 1): self 返回一个新实例,其值增加给定值。

  • multiply(int|float|self $number): self 返回一个新实例,其值为当前值与给定数的乘积。

  • power(int|float|self $exponent): self 返回一个self实例,其值为当前值的$exponent次幂。

  • square(): self 返回当前值的平方的self实例。

  • squareRoot(): self 返回一个self实例,其值为当前值的平方根。

  • subtract(int|float|self $number): self 返回一个self实例,其值为当前值减去$number。

  • subtractTo(int|float|self $number): self 返回一个self实例,其值为$number减去当前值。

  • toFloat(): float 返回当前值作为整数的self实例。

  • toInteger(): int 返回当前值作为整数的self实例。

  • value(): int|float 返回当前值。

  • static of(int|float $number): self 返回给定数的self实例。

  • static zero(): self 返回值为0的self实例。

## 下一个版本

也许在《Numerik》类中会有更多的计算方法,包括三角函数(cos, sin, tan...)。如果需要的话,还可能有一些其他在《PrimalString》中的方法...

布尔类型是否需要这种考虑?布尔值要么为true,要么为false,要么有效,要么无效...我应该实现什么?一个valid()方法就足够了吗?《hypothetik》包已经能够通过适当的管理处理布尔类型。