mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-14 03:40:38 -07:00
fix: slice filter on negative begin, #117
This commit is contained in:
@@ -9,8 +9,8 @@ export default {
|
||||
'sort': <T>(v: T[], arg: (lhs: T, rhs: T) => number) => v.sort(arg),
|
||||
'size': (v: string | any[]) => v.length,
|
||||
'concat': <T1, T2>(v: T1[], arg: T2[] | T2): Array<T1 | T2> => Array.prototype.concat.call(v, arg),
|
||||
'slice': <T>(v: T[], begin: number, length: number): T[] => {
|
||||
if (length === undefined) length = 1
|
||||
'slice': <T>(v: T[], begin: number, length: number = 1): T[] => {
|
||||
begin = begin < 0 ? v.length + begin : begin
|
||||
return v.slice(begin, begin + length)
|
||||
},
|
||||
'uniq': function<T> (arr: T[]): T[] {
|
||||
|
||||
@@ -43,6 +43,7 @@ describe('filters/array', function () {
|
||||
it('should slice third char by 2', () => test('{{ "Liquid" | slice: 2 }}', 'q'))
|
||||
it('should slice substr by 2,5', () => test('{{ "Liquid" | slice: 2, 5 }}', 'quid'))
|
||||
it('should slice substr by -3,2', () => test('{{ "Liquid" | slice: -3, 2 }}', 'ui'))
|
||||
it('should slice substr by -2,2', () => test('{{ "abc" | slice: -2, 2 }}', 'bc'))
|
||||
it('should support array', () => test('{{ "1,2,3,4" | split: "," | slice: 1,2 | join }}', '2 3'))
|
||||
})
|
||||
it('should support sort', function () {
|
||||
|
||||
Reference in New Issue
Block a user