Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tempura

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tempura - npm Package Compare versions

Comparing version 0.1.0-next.0 to 0.1.0-next.1

utils/index.d.ts

125

dist/index.js

@@ -1,123 +0,16 @@

const ENDLINES = /[\r\n]+$/g;
const CURLY = /{{{?\s*([\s\S]*?)\s*}}}?/g;
const ESCAPE = /[&"<]/g, CHARS = {
'"': '&quot;',
'&': '&amp;',
'<': '&lt',
};
const utils = require('tempura/utils');
// $$1 = escape(); $$2 = template values
function transform(input, options) {
options = options || {};
let char, num, action, tmp;
let last = CURLY.lastIndex = 0;
let wip='', txt='', match, inner;
let extra = options.extra || {};
let minify = !!options.minify, stack=[];
let initials = new Set(options.props || []);
function close() {
if (wip.length > 0) {
txt += (txt ? 'x+=' : '=') + '`' + (minify ? wip.replace(/([\t\s]+(?=<|$)|(\r?\n)+)/g, '') : wip) + '`;';
} else if (txt.length === 0) {
txt = '="";'
}
wip = '';
}
while (match = CURLY.exec(input)) {
wip += input.substring(last, match.index).replace(ENDLINES, '');
last = match.index + match[0].length;
inner = match[1].trim();
char = inner.charAt(0);
if (char === '!') {
// comment, continue
} else if (char === '#') {
close();
[, action, inner] = /^#\s*([a-zA-Z]+)\s*(.*)/.exec(inner);
if (action === 'expect') {
inner.trim().split(/[\n\r\s\t]*,[\n\r\s\t]*/g).forEach(key => {
initials.add(key);
});
} else if (action === 'var') {
num = inner.indexOf('=');
tmp = inner.substring(0, num++).trim();
inner = inner.substring(num).trim().replace(/[;]$/, '');
txt += `var ${tmp}=${inner};`;
} else if (action === 'each') {
num = inner.indexOf(' as ');
stack.push(action);
if (!~num) {
txt += `for(var i=0,$$a=${inner.trim()};i<$$a.length;i++){`;
} else {
tmp = inner.substring(0, num).trim();
inner = inner.substring(num + 4).trim();
let [item, idx='i'] = inner.replace(/[()\s]/g, '').split(','); // (item, idx?)
txt += `for(var ${idx}=0,${item},$$a=${tmp};${idx}<$$a.length;${idx}++){${item}=$$a[${idx}];`;
}
} else if (action === 'if') {
txt += `if(${inner.trim()}){`;
stack.push(action);
} else if (action === 'elif') {
txt += `}else if(${inner.trim()}){`;
} else if (action === 'else') {
txt += `}else{`;
} else if (tmp = extra[action]) {
if (inner = tmp(inner, match[0])) {
if (!inner.endsWith(';')) inner += ';';
txt += inner;
}
} else {
throw new Error(`Unknown "${action}" block`);
}
} else if (char === '/') {
action = inner.substring(1);
inner = stack.pop();
close();
if (action === inner) txt += '}';
else if (inner === 'if' && (action === 'else' || action === 'elif')) txt += '}';
else throw new Error(`Expected to close "${inner}" block; closed "${action}" instead`);
} else if (match[0].charAt(2) === '{') {
wip += '${' + inner + '}'; // {{{ raw }}}
} else {
wip += '${$$1(' + inner + ')}';
}
}
if (stack.length > 0) {
throw new Error(`Unterminated "${stack.pop()}" block`);
}
if (last < input.length) {
wip += input.substring(last).replace(ENDLINES, '');
}
close();
tmp = initials.size ? `{${ [...initials].join() }}=$$2,x` : ' x';
return `var${tmp + txt}return x`;
function compile(input, options={}) {
return new Function('$$1', '$$2', '$$3', utils.gen(input, options)).bind(0, options.escape || utils.esc, options.blocks);
}
function compile(body, options) {
let esc = options && options.escape || toEscape;
return new Function('$$1', '$$2', body).bind(0, esc);
function transform(input, options={}) {
return (
options.format === 'cjs'
? 'var{esc:$$1}=require("tempura/utils");module.exports='
: 'import{esc as $$1}from"tempura/utils";export default '
) + 'function($$3,$$2){'+utils.gen(input, options)+'}';
}
function toEscape(value) {
if (typeof value !== 'string') return value;
let last=ESCAPE.lastIndex=0, tmp=0, out='';
while (ESCAPE.test(value)) {
tmp = ESCAPE.lastIndex - 1;
out += value.substring(last, tmp) + CHARS[value[tmp]];
last = tmp + 1;
}
return out + value.substring(last);
}
exports.compile = compile;
exports.transform = transform;

@@ -1,13 +0,6 @@

export function transform(input: string, options?: {
props?: string[];
minify?: boolean;
extra?: {
[directive: string]: (inner: string, full: string) => string;
}
}): string;
import type { Options } from 'tempura/utils';
import { esc } from 'tempura/utils';
export type Compiler = <T extends Record<string, any>> (data: T) => string;
export function compile(template: string, options?: {
escape?: <T=unknown>(value: T) => T|string;
}): Compiler;
export function compile(input: string, options?: Options & { escape?: typeof esc; }): Compiler;
export function transform(input: string, options?: Options & { format?: 'esm' | 'cjs' }): string;
{
"name": "tempura",
"version": "0.1.0-next.0",
"version": "0.1.0-next.1",
"repository": "lukeed/tempura",
"description": "WIP",
"unpkg": "dist/index.min.js",
"module": "dist/index.mjs",

@@ -21,6 +20,7 @@ "main": "dist/index.js",

"build": "bundt",
"test": "uvu -r esm test"
"test": "uvu -r esm -r module-alias/register test"
},
"files": [
"*.d.ts",
"utils",
"dist"

@@ -33,11 +33,22 @@ ],

},
"./utils": {
"import": "./utils/index.mjs",
"require": "./utils/index.js"
},
"./package.json": "./package.json"
},
"keywords": [
],
"modes": {
"utils": "src/utils.js",
"default": "src/index.js"
},
"keywords": [],
"devDependencies": {
"bundt": "1.1.1",
"bundt": "1.1.3",
"esm": "3.2.25",
"module-alias": "2.2.2",
"uvu": "0.5.1"
},
"_moduleAliases": {
"tempura/utils": "src/utils.js"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc