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'); // falseReference
function isNotLike(pattern: string | RegExp): (input: string) => booleanParameters
| Parameter | Type | Description |
|---|---|---|
pattern | string | RegExp | Pattern 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'); // falseExample: 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
RegExpusingnew RegExp(pattern). UseRegExpobjects directly for better control over flags like case-insensitivity (/pattern/i).
Related
- isLike - Pattern matching predicate
- isNotIn - Array exclusion check
- doesStartWith - Check string prefix
- doesEndWith - Check string suffix
- isString - Type guard for strings