@@ -593,19 +593,68 @@ export const any = when(isUnknown);
593593export const _ = any ;
594594
595595/**
596- * `P.string` is a wildcard pattern matching any **string**.
596+ * `P.string.startsWith(start)` is a pattern, matching **strings** starting with `start`.
597+ *
598+ * [Read documentation for `P.string.startsWith` on GitHub](https://github.com/gvergnaud/ts-pattern#PstringstartsWith)
599+ *
600+ * @example
601+ * match(value)
602+ * .with(P.string.startsWith('A'), () => 'value starts with an A')
603+ */
604+
605+ const startsWith = < input , const start extends string > (
606+ start : start
607+ ) : GuardP < input , `${start } ${string } `> =>
608+ when ( ( value ) => isString ( value ) && value . startsWith ( start ) ) ;
609+
610+ /**
611+ * `P.string.endsWith(end)` is a pattern, matching **strings** ending with `end`.
612+ *
613+ * [Read documentation for `P.string.endsWith` on GitHub](https://github.com/gvergnaud/ts-pattern#PstringendsWith)
614+ *
615+ * @example
616+ * match(value)
617+ * .with(P.string.endsWith('!'), () => 'value ends with an !')
618+ */
619+ const endsWith = < input , const end extends string > (
620+ end : end
621+ ) : GuardP < input , `${string } ${end } `> =>
622+ when ( ( value ) => isString ( value ) && value . endsWith ( end ) ) ;
623+
624+ /**
625+ * `P.string.includes(substr)` is a pattern, matching **strings** containing `substr`.
626+ *
627+ * [Read documentation for `P.string.includes` on GitHub](https://github.com/gvergnaud/ts-pattern#Pstringincludes)
628+ *
629+ * @example
630+ * match(value)
631+ * .with(P.string.includes('http'), () => 'value contains http')
632+ */
633+ const includes = < input , const substr extends string > (
634+ substr : substr
635+ ) : GuardExcludeP < input , string , never > =>
636+ when ( ( value ) => isString ( value ) && value . includes ( substr ) ) ;
637+
638+ const assignStringMethods = < p extends GuardP < any , any > > ( pattern : p ) =>
639+ Object . assign ( pattern , {
640+ startsWith,
641+ endsWith,
642+ includes,
643+ } ) ;
644+
645+ /**
646+ * `P.string` is a wildcard pattern, matching any **string**.
597647 *
598648 * [Read documentation for `P.string` on GitHub](https://github.com/gvergnaud/ts-pattern#Pstring-wildcard)
599649 *
600650 * @example
601651 * match(value)
602652 * .with(P.string, () => 'will match on strings')
603653 */
604-
605- export const string = when ( isString ) ;
654+ export const string = assignStringMethods ( when ( isString ) ) ;
606655
607656/**
608- * `P.number` is a wildcard pattern matching any **number**.
657+ * `P.number` is a wildcard pattern, matching any **number**.
609658 *
610659 * [Read documentation for `P.number` on GitHub](https://github.com/gvergnaud/ts-pattern#Pnumber-wildcard)
611660 *
@@ -616,7 +665,7 @@ export const string = when(isString);
616665export const number = when ( isNumber ) ;
617666
618667/**
619- * `P.boolean` is a wildcard pattern matching any **boolean**.
668+ * `P.boolean` is a wildcard pattern, matching any **boolean**.
620669 *
621670 * [Read documentation for `P.boolean` on GitHub](https://github.com/gvergnaud/ts-pattern#boolean-wildcard)
622671 *
@@ -626,7 +675,7 @@ export const number = when(isNumber);
626675export const boolean = when ( isBoolean ) ;
627676
628677/**
629- * `P.bigint` is a wildcard pattern matching any **bigint**.
678+ * `P.bigint` is a wildcard pattern, matching any **bigint**.
630679 *
631680 * [Read documentation for `P.bigint` on GitHub](https://github.com/gvergnaud/ts-pattern#bigint-wildcard)
632681 *
@@ -636,7 +685,7 @@ export const boolean = when(isBoolean);
636685export const bigint = when ( isBigInt ) ;
637686
638687/**
639- * `P.symbol` is a wildcard pattern matching any **symbol**.
688+ * `P.symbol` is a wildcard pattern, matching any **symbol**.
640689 *
641690 * [Read documentation for `P.symbol` on GitHub](https://github.com/gvergnaud/ts-pattern#symbol-wildcard)
642691 *
@@ -646,7 +695,7 @@ export const bigint = when(isBigInt);
646695export const symbol = when ( isSymbol ) ;
647696
648697/**
649- * `P.nullish` is a wildcard pattern matching **null** or **undefined**.
698+ * `P.nullish` is a wildcard pattern, matching **null** or **undefined**.
650699 *
651700 * [Read documentation for `P.nullish` on GitHub](https://github.com/gvergnaud/ts-pattern#nullish-wildcard)
652701 *
0 commit comments