Packages@accelint/predicates
doesEndWith
Curried predicate for testing if strings end with a specific suffix
Creates a predicate function that determines if a string ends with a specific suffix.
Usage
import { doesEndWith } from '@accelint/predicates';
const isJsFile = doesEndWith('.js');
isJsFile('app.js'); // true
isJsFile('style.css'); // falseReference
function doesEndWith(suffix: string): (input: string) => booleanParameters
| Parameter | Type | Description |
|---|---|---|
suffix | string | The substring to use as the suffix |
Returns
Curried function that accepts a string and returns true if it ends with the suffix.
Examples
Example: File extension filtering
import { doesEndWith } from '@accelint/predicates';
const isImageFile = doesEndWith('.jpg');
const isConfigFile = doesEndWith('.json');
const files = ['avatar.jpg', 'config.json', 'script.js', 'photo.jpg'];
const images = files.filter(doesEndWith('.jpg'));
// ['avatar.jpg', 'photo.jpg']Example: Email domain validation
import { doesEndWith } from '@accelint/predicates';
const isCompanyEmail = doesEndWith('@company.com');
function validateEmail(email: string): boolean {
return isCompanyEmail(email);
}
validateEmail('user@company.com'); // true
validateEmail('user@external.com'); // falseGood to know: Comparisons are case-sensitive. Use native String methods like
.toLowerCase()before applying this predicate if case-insensitive matching is needed.
Related
- doesStartWith - Check if string starts with prefix
- doesNotStartWith - Check if string does not start with prefix
- doesNotEndWith - Negated version of this function
- isLike - Pattern matching with RegExp
- isNotLike - Negated pattern matching
- isString - Type guard for strings