Standard Toolkit
Packages@accelint/predicates

isNotLike

Curried predicate for testing strings that do not match patterns or regular expressions

Creates a predicate that determines if a string does not match a given pattern or regular expression.

Usage

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

const isNotEmail = isNotLike(/^[^\s@]+@[^\s@]+\.[^\s@]+$/);
isNotEmail('invalid-email');    // true
isNotEmail('user@example.com'); // false

Reference

function isNotLike(pattern: string | RegExp): (input: string) => boolean

Parameters

ParameterTypeDescription
patternstring | RegExpPattern to match (strings are converted to RegExp)

Returns

Curried function that accepts a string and returns true if it does not match the pattern.

Examples

Example: Excluding test files

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

const isNotTestFile = isNotLike(/\.test\.(js|ts)$/);

const files = ['app.js', 'app.test.js', 'utils.ts', 'utils.test.ts'];
const sourceFiles = files.filter(isNotTestFile);
// ['app.js', 'utils.ts']

Example: Filtering non-numeric strings

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

const hasNoNumbers = isNotLike(/\d/);

const items = ['abc', '123', 'def', 'a1b2'];
const textOnly = items.filter(hasNoNumbers);
// ['abc', 'def']

Example: Excluding special characters

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

const hasNoSpecialChars = isNotLike(/[^a-zA-Z0-9]/);

function isValidUsername(name: string): boolean {
  return hasNoSpecialChars(name) && name.length >= 3;
}

isValidUsername('john123');   // true
isValidUsername('john@123');  // false
isValidUsername('jd');        // false

Example: File processing pipeline

import { isLike, isNotLike } from '@accelint/predicates';

const isSourceFile = isLike(/\.(ts|tsx)$/);
const isNotTestFile = isNotLike(/\.(test|spec)\.(ts|tsx)$/);
const isNotConfigFile = isNotLike(/^(tsconfig|vite\.config|vitest\.config)/);

function getSourceFiles(files: string[]): string[] {
  return files
    .filter(isSourceFile)
    .filter(isNotTestFile)
    .filter(isNotConfigFile);
}

const allFiles = [
  'src/app.ts',
  'src/app.test.ts',
  'src/utils.ts',
  'tsconfig.json',
  'vite.config.ts'
];

const sources = getSourceFiles(allFiles);
// ['src/app.ts', 'src/utils.ts']

Good to know: When passing strings as patterns, they are converted to RegExp using new RegExp(pattern). Use RegExp objects directly for better control over flags like case-insensitivity (/pattern/i).

On this page