Standard Toolkit
Packages@accelint/predicates

doesStartWith

Curried predicate for testing if strings start with a specific prefix

Creates a predicate function that determines if a string starts with a specific prefix.

Usage

import { doesStartWith } from '@accelint/predicates';

const isHttpUrl = doesStartWith('http');
isHttpUrl('https://example.com'); // true
isHttpUrl('ftp://example.com');   // false

Reference

function doesStartWith(prefix: string): (input: string) => boolean

Parameters

ParameterTypeDescription
prefixstringThe substring to use as the prefix

Returns

Curried function that accepts a string and returns true if it starts with the prefix.

Examples

Example: URL validation

import { doesStartWith } from '@accelint/predicates';

const isHttps = doesStartWith('https://');
const isHttp = doesStartWith('http://');

function isSecureUrl(url: string): boolean {
  return isHttps(url);
}

isSecureUrl('https://example.com'); // true
isSecureUrl('http://example.com');  // false

Example: Filtering file paths

import { doesStartWith } from '@accelint/predicates';

const paths = [
  '/home/user/documents',
  '/var/log/system',
  '/home/user/downloads',
  '/etc/config'
];

const userPaths = paths.filter(doesStartWith('/home/user'));
// ['/home/user/documents', '/home/user/downloads']

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