imbrn / v8n

☑️ JavaScript fluent validation library

Home Page:https://imbrn.github.io/v8n

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: last() and first() should work for strings longer than 1, too

h34dless opened this issue · comments

The same way as include() - first() and last() should validate to true when tested like v8n().last('.yaml').test('file.yaml')

This seems to make sense to me, but we can't actually change that behavior because of compatibility issues. So, maybe what we can do is to create specific rules for this purpose.

But if you want to override the first and last behavior in your application, that 's pretty easy:

v8n.extend({
    first: str => value => value.startsWith(str),
	last: str => value => value.endsWith(str)
});

v8n().first("file").test("file.yaml"); // true
v8n().last(".yaml").test("file.yaml"); // true