imbrn/v8n

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

h34dless opened this issue · 1 comments

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

imbrn commented

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