Socket
Socket
Sign inDemoInstall

edge.js

Package Overview
Dependencies
11
Maintainers
2
Versions
64
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.0.0-2 to 6.0.0-3

build/index-a4452d69.d.ts

2

build/index.d.ts

@@ -1,2 +0,2 @@

export { h as Edge } from './index-d8c609be.js';
export { j as Edge } from './index-a4452d69.js';
import 'edge-parser';

@@ -3,0 +3,0 @@ import 'edge-lexer/types';

@@ -8,5 +8,7 @@ var __defProp = Object.defineProperty;

// src/loader.ts
import { readFileSync } from "node:fs";
import { slash } from "@poppinss/utils";
import { fileURLToPath } from "node:url";
import string from "@poppinss/utils/string";
import { join, isAbsolute } from "node:path";
import { existsSync, readFileSync, readdirSync } from "node:fs";
var Loader = class {

@@ -37,2 +39,27 @@ /**

/**
* Returns a list of components for a given disk
*/
#getDiskComponents(diskName) {
const componentsDirName = "components";
const diskBasePath = this.#mountedDirs.get(diskName);
if (!existsSync(join(diskBasePath, componentsDirName))) {
return [];
}
const files = readdirSync(join(diskBasePath, componentsDirName), {
recursive: true,
encoding: "utf8"
}).filter((file) => file.endsWith(".edge"));
return files.map((file) => {
const fileName = slash(file).replace(/\.edge$/, "");
const componentPath = `${componentsDirName}/${fileName}`;
const tagName = fileName.split("/").filter((segment, index) => {
return index === 0 || segment !== "index";
}).map((segment) => string.camelCase(segment)).join(".");
return {
componentName: diskName !== "default" ? `${diskName}::${componentPath}` : componentPath,
tagName: diskName !== "default" ? `${diskName}.${tagName}` : tagName
};
});
}
/**
* Extracts the disk name and the template name from the template

@@ -91,3 +118,3 @@ * path expression.

* {
* 'form.label': { template: '/users/virk/code/app/form/label' }
* 'form.label': { template: 'Template contents' }
* }

@@ -209,2 +236,20 @@ * ```

}
/**
* Returns a list of components from all the disks. We assume
* the components are stored within the components directory.
*
* Also, we treat all in-memory templates as components.
*
* The return path is same the path you will pass to the `@component`
* tag.
*/
listComponents() {
const diskNames = [...this.#mountedDirs.keys()];
return diskNames.map((diskName) => {
return {
diskName,
components: this.#getDiskComponents(diskName)
};
});
}
};

@@ -1661,2 +1706,78 @@

// src/edge/globals.ts
import stringify from "js-stringify";
import classNames2 from "classnames";
import inspect from "@poppinss/inspect";
import string2 from "@poppinss/utils/string";
var edgeGlobals = {
/**
* Converts new lines to break
*/
nl2br: (value) => {
if (!value) {
return;
}
return String(value).replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, "$1<br>");
},
/**
* Inspect state
*/
inspect: (value) => {
return htmlSafe(inspect.string.html(value));
},
/**
* Truncate a sentence
*/
truncate: (value, length = 20, options) => {
options = options || {};
return string2.truncate(value, length, {
completeWords: options.completeWords !== void 0 ? options.completeWords : !options.strict,
suffix: options.suffix
});
},
/**
* Generate an excerpt
*/
excerpt: (value, length = 20, options) => {
options = options || {};
return string2.excerpt(value, length, {
completeWords: options.completeWords !== void 0 ? options.completeWords : !options.strict,
suffix: options.suffix
});
},
/**
* Helpers related to HTML
*/
html: {
escape,
safe: htmlSafe,
classNames: classNames2,
attrs: (values) => {
return htmlSafe(stringifyAttributes(values));
}
},
/**
* Helpers related to JavaScript
*/
js: {
stringify
},
camelCase: string2.camelCase,
snakeCase: string2.snakeCase,
dashCase: string2.dashCase,
pascalCase: string2.pascalCase,
capitalCase: string2.capitalCase,
sentenceCase: string2.sentenceCase,
dotCase: string2.dotCase,
noCase: string2.noCase,
titleCase: string2.titleCase,
pluralize: string2.pluralize,
sentence: string2.sentence,
prettyMs: string2.milliseconds.format,
toMs: string2.milliseconds.parse,
prettyBytes: string2.bytes.format,
toBytes: string2.bytes.parse,
ordinal: string2.ordinal
};
// src/processor.ts

@@ -1802,2 +1923,66 @@ var Processor = class {

// src/plugins/supercharged.ts
var SuperChargedComponents = class {
#edge;
#components = {};
constructor(edge) {
this.#edge = edge;
this.#claimTags();
this.#transformTags();
}
/**
* Refreshes the list of components
*/
refreshComponents() {
this.#components = this.#edge.loader.listComponents().reduce((result, { components }) => {
components.forEach((component) => {
result[component.tagName] = component.componentName;
});
return result;
}, {});
}
/**
* Registers hook to claim self processing of tags that
* are references to components
*/
#claimTags() {
this.#edge.compiler.claimTag((name) => {
if (this.#components[name]) {
return { seekable: true, block: true };
}
return null;
});
this.#edge.asyncCompiler.claimTag((name) => {
if (this.#components[name]) {
return { seekable: true, block: true };
}
return null;
});
}
/**
* Transforms tags to component calls
*/
#transformTags() {
this.#edge.processor.process("tag", ({ tag }) => {
const component = this.#components[tag.properties.name];
if (!component) {
return;
}
tag.properties.name = "component";
if (tag.properties.jsArg.trim() === "") {
tag.properties.jsArg = `'${component}'`;
} else {
tag.properties.jsArg = `'${component}',${tag.properties.jsArg}`;
}
});
}
};
var superCharged;
var pluginSuperCharged = (edge, firstRun) => {
if (firstRun) {
superCharged = new SuperChargedComponents(edge);
}
superCharged.refreshComponents();
};
// src/edge/main.ts

@@ -1845,3 +2030,3 @@ var Edge = class _Edge {

*/
globals = {};
globals = edgeGlobals;
/**

@@ -1865,2 +2050,3 @@ * List of registered tags. Adding new tags will only impact

});
this.use(pluginSuperCharged, { recurring: !options.cache });
}

@@ -1867,0 +2053,0 @@ /**

export * from 'edge-lexer/types';
import 'edge-parser';
export * from 'edge-parser/types';
export { c as CacheManagerContract, C as CompiledTemplate, d as CompilerOptions, g as EdgeBufferContract, E as EdgeOptions, a as LoaderContract, L as LoaderTemplate, e as ParserContract, P as PluginFn, T as TagContract, f as TagTokenContract, b as TagsContract } from '../index-d8c609be.js';
export { d as CacheManagerContract, c as CompiledTemplate, e as CompilerOptions, C as ComponentsTree, i as EdgeBufferContract, f as EdgeGlobals, E as EdgeOptions, a as LoaderContract, L as LoaderTemplate, g as ParserContract, P as PluginFn, T as TagContract, h as TagTokenContract, b as TagsContract } from '../index-a4452d69.js';
import '@poppinss/macroable';
{
"name": "edge.js",
"description": "Template engine",
"version": "6.0.0-2",
"version": "6.0.0-3",
"engines": {

@@ -6,0 +6,0 @@ "node": ">=18.16.0"

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc