mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
fix: array output now join with "" instead of ","
This commit is contained in:
@@ -32,6 +32,7 @@ export function stringify (value: any): string {
|
|||||||
value = toValue(value)
|
value = toValue(value)
|
||||||
if (isString(value)) return value
|
if (isString(value)) return value
|
||||||
if (isNil(value)) return ''
|
if (isNil(value)) return ''
|
||||||
|
if (isArray(value)) return value.map(x => stringify(x)).join('')
|
||||||
return String(value)
|
return String(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -103,7 +103,7 @@ describe('Issues', function () {
|
|||||||
const html = await engine.parseAndRender(
|
const html = await engine.parseAndRender(
|
||||||
`{{ 'a \n b \n c' | newline_to_br | split: '<br />' }}`
|
`{{ 'a \n b \n c' | newline_to_br | split: '<br />' }}`
|
||||||
)
|
)
|
||||||
expect(html).to.equal('a ,\n b ,\n c')
|
expect(html).to.equal('a \n b \n c')
|
||||||
})
|
})
|
||||||
it('#342 New lines in logical operator', async () => {
|
it('#342 New lines in logical operator', async () => {
|
||||||
const engine = new Liquid()
|
const engine = new Liquid()
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ describe('.parseAndRender()', function () {
|
|||||||
it('should stringify array ', async function () {
|
it('should stringify array ', async function () {
|
||||||
var ctx = { arr: [-2, 'a'] }
|
var ctx = { arr: [-2, 'a'] }
|
||||||
const html = await engine.parseAndRender('{{arr}}', ctx)
|
const html = await engine.parseAndRender('{{arr}}', ctx)
|
||||||
return expect(html).to.equal('-2,a')
|
return expect(html).to.equal('-2a')
|
||||||
})
|
})
|
||||||
it('should render undefined as empty', async function () {
|
it('should render undefined as empty', async function () {
|
||||||
const html = await engine.parseAndRender('foo{{zzz}}bar', {})
|
const html = await engine.parseAndRender('foo{{zzz}}bar', {})
|
||||||
@@ -41,9 +41,9 @@ describe('.parseAndRender()', function () {
|
|||||||
const ctx = { obj: [1, 2] }
|
const ctx = { obj: [1, 2] }
|
||||||
const template = engine.parse('{{obj}}')
|
const template = engine.parse('{{obj}}')
|
||||||
const result = await engine.render(template, ctx)
|
const result = await engine.render(template, ctx)
|
||||||
expect(result).to.equal('1,2')
|
expect(result).to.equal('12')
|
||||||
const result2 = await engine.render(template, ctx)
|
const result2 = await engine.render(template, ctx)
|
||||||
expect(result2).to.equal('1,2')
|
expect(result2).to.equal('12')
|
||||||
})
|
})
|
||||||
it('should support the "join" filter', async function () {
|
it('should support the "join" filter', async function () {
|
||||||
var ctx = { names: ['alice', 'bob'] }
|
var ctx = { names: ['alice', 'bob'] }
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ describe('filters/array', function () {
|
|||||||
describe('map', () => {
|
describe('map', () => {
|
||||||
it('should support map', function () {
|
it('should support map', function () {
|
||||||
const posts = [{ category: 'foo' }, { category: 'bar' }]
|
const posts = [{ category: 'foo' }, { category: 'bar' }]
|
||||||
return test('{{posts | map: "category"}}', { posts }, 'foo,bar')
|
return test('{{posts | map: "category"}}', { posts }, 'foobar')
|
||||||
})
|
})
|
||||||
it('should normalize non-array input', function () {
|
it('should normalize non-array input', function () {
|
||||||
const post = { category: 'foo' }
|
const post = { category: 'foo' }
|
||||||
@@ -53,7 +53,7 @@ describe('filters/array', function () {
|
|||||||
describe('compact', () => {
|
describe('compact', () => {
|
||||||
it('should compact array', function () {
|
it('should compact array', function () {
|
||||||
const posts = [{ category: 'foo' }, { category: 'bar' }, { foo: 'bar' }]
|
const posts = [{ category: 'foo' }, { category: 'bar' }, { foo: 'bar' }]
|
||||||
return test('{{posts | map: "category" | compact}}', { posts }, 'foo,bar')
|
return test('{{posts | map: "category" | compact}}', { posts }, 'foobar')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
describe('reverse', function () {
|
describe('reverse', function () {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ describe('tags/assign', function () {
|
|||||||
it('should assign as array', async function () {
|
it('should assign as array', async function () {
|
||||||
const src = '{% assign foo=(1..3) %}{{foo}}'
|
const src = '{% assign foo=(1..3) %}{{foo}}'
|
||||||
const html = await liquid.parseAndRender(src)
|
const html = await liquid.parseAndRender(src)
|
||||||
return expect(html).to.equal('1,2,3')
|
return expect(html).to.equal('123')
|
||||||
})
|
})
|
||||||
it('should assign as filter result', async function () {
|
it('should assign as filter result', async function () {
|
||||||
const src = '{% assign foo="a b" | capitalize | split: " " | first %}{{foo}}'
|
const src = '{% assign foo="a b" | capitalize | split: " " | first %}{{foo}}'
|
||||||
|
|||||||
Reference in New Issue
Block a user