Standard Toolkit
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'); // false

Reference

function doesEndWith(suffix: string): (input: string) => boolean

Parameters

ParameterTypeDescription
suffixstringThe 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');   // false

Good to know: Comparisons are case-sensitive. Use native String methods like .toLowerCase() before applying this predicate if case-insensitive matching is needed.

On this page