0.0.3 • Published 12 months ago

utils-liquid v0.0.3

Weekly downloads
-
License
-
Repository
-
Last release
12 months ago

utils-liquid

This library was generated with Nx.

Building

Run nx build utils-liquid to build the library.

Use

Import library imoprt { LiquidJS } from "utils-liquid"

Testing

Following are the examples to test with jest

import { LiquidJS } from 'utils-liquid';

describe('compiles liquid templates', () => {
  const liquid = new LiquidJS();
  it('parses simple template', () => {
    const parsed = liquid.parse('123 {{foo}}');
    expect(parsed).toBeDefined();
  });

  it('renders simple template', async () => {
    const parsed = liquid.parse('123 {{foo}}');
    expect(await liquid.render(parsed, { foo: 'wowow' })).toEqual('123 wowow');
  });

  it('renders with json filter', async () => {
    const parsed = liquid.parse('123 {{foo | json}}');
    expect(await liquid.render(parsed, { foo: { val: true } })).toEqual(
      '123 {"val":true}'
    );
    const parsed1 = liquid.parse('123 {{foo | json: 2}}');
    expect(await liquid.render(parsed1, { foo: { val: true } })).toEqual(
      '123 {\n  "val": true\n}'
    );
  });

  it('renders with get_file_from_data_url filter', async () => {
    const parsed = liquid.parse('123 {{foo | get_file_from_data_url}}');
    expect(await liquid.render(parsed, { foo: 'data:;name=wow.txt;' })).toEqual(
      '123 wow.txt'
    );
    expect(await liquid.render(parsed, { foo: 'broken' })).toEqual('123 ');
  });

  it('renders with base64_encode filter', async () => {
    const parsed = liquid.parse('123 {{foo | base64_encode}}');
    expect(await liquid.render(parsed, { foo: 'hello world' })).toEqual(
      '123 aGVsbG8gd29ybGQ='
    );
  });
});
0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

12 months ago