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

@emdaer/core

Package Overview
Dependencies
Maintainers
2
Versions
135
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@emdaer/core - npm Package Compare versions

Comparing version 1.0.0-alpha.11 to 1.0.0-beta.0

lib/util/addStamp.js

57

lib/index.js
/* */
const { NO_CONTENT, NO_DESTINATION, NO_GENERATED } = require('./_errors');
const combineContent = require('./util/combineContent');
const addStamp = require('./util/addStamp');
const executePlugins = require('./util/executePlugins');
const applyTransforms = require('./util/applyTransforms');
const fs = require('fs-extra');
/**
* An instance of Emdaer corresponding to a document
*
* @param options
* @param {string|undefined} options.destination The path at which to write the document
* @param {Array<PluginCall>} options.content A list defining which plugins to call with what options
* @param {Array<TransformCall>} options.transforms A list defining which transforms to call with what options
*/
module.exports = class Emdaer {
constructor(options) {
if (
typeof options.destination !== 'string' ||
!options.destination.length
) {
throw new Error(NO_DESTINATION);
}
if (!Array.isArray(options.content) || !options.content.length) {
throw new Error(NO_CONTENT);
}
Object.assign(this, {
destination: options.destination,
content: options.content,
transforms: (options && options.transforms) || null,
});
}
/**
* Generates the document
*
* @returns {Promise<string>} Resolves with the generated document
*/
async generate() {
this.generated = await applyTransforms(
this.transforms,
combineContent(await executePlugins(this.content))
);
return this.generated;
}
/**
* Writes the document
*
* @returns {Promise<void>} Resolves when the document has been written
*/
async write() {
if (!this.generated) {
throw new Error(NO_GENERATED);
}
return fs.outputFile(this.destination, this.generated);
}
module.exports = async function emdaer(origin, content) {
return addStamp(await applyTransforms(await executePlugins(content)), origin);
};
/* */
const { safeLoad } = require('js-yaml');
const resolveTransform = require('../../src/util/resolveTransform');
const applyTransform = require('./applyTransform');
/**
* Applies provided transforms to generated content
* Applies transforms to generated content
*/
module.exports = async (
transforms,
module.exports = async function applyTransforms(
content
) => {
if (!transforms) {
return Promise.resolve(content);
}
return transforms.reduce(
async (
acc,
[transform, options]
) => resolveTransform(transform)(await acc, options),
Promise.resolve(content)
);
) {
const replacementContent = content;
const matches = replacementContent.match(/<!--emdaer-t[\s\S]*?-->/g) || [];
return matches.reduce((acc, match) => {
const [, , body] = /(<!--emdaer-t)([\s\S]*?)(-->)/g.exec(match);
return (async () => {
const accContent = await acc;
return applyTransform(accContent, safeLoad(body));
})();
}, Promise.resolve(replacementContent));
};

@@ -7,3 +7,3 @@ /* */

const executeNested = async (options) => {
async function executeNested(options) {
if (options && options.from) {

@@ -16,3 +16,3 @@ const [utilityPlugin, utilityOptions] = options.from;

return options;
};
}

@@ -22,5 +22,6 @@ /**

*/
const executePlugin = async ([plugin, options]) =>
resolvePlugin(plugin)(await executeNested(options));
async function executePlugin([plugin, options]) {
return (await resolvePlugin(plugin))(await executeNested(options));
}
module.exports = executePlugin;
/* */
const { safeLoad } = require('js-yaml');

@@ -7,9 +8,17 @@ const executePlugin = require('./executePlugin');

/**
* Executes provided plugins to generate content
* Finds and executes plugins
*/
module.exports = async (content) =>
Promise.all(
content.map((pluginCall) =>
executePlugin(pluginCall)
)
);
module.exports = async function executePlugins(
content
) {
const replacementContent = content;
const matches = replacementContent.match(/<!--emdaer-p[\s\S]*?-->/g) || [];
return matches.reduce((acc, match) => {
const [comment, , body] = /(<!--emdaer-p)([\s\S]*?)(-->)/g.exec(match);
return (async () => {
const accContent = await acc;
return accContent.replace(comment, await executePlugin(safeLoad(body)));
})();
}, Promise.resolve(replacementContent));
};

@@ -9,5 +9,5 @@ /* */

*/
module.exports = (pluginName) => {
module.exports = function resolvePlugin(pluginName) {
try {
return require(`@emdaer/plugin-${pluginName}`);
return require(pluginName);
} catch (error) {

@@ -14,0 +14,0 @@ throw new Error(`${NO_PLUGIN}: ${pluginName}`);

@@ -9,5 +9,5 @@ /* */

*/
module.exports = (transformName) => {
module.exports = function resolveTransform(transformName) {
try {
return require(`@emdaer/transform-${transformName}`);
return require(transformName);
} catch (error) {

@@ -14,0 +14,0 @@ throw new Error(`${NO_TRANSFORM}: ${transformName}`);

{
"name": "@emdaer/core",
"description": "emdaer core",
"version": "1.0.0-alpha.11",
"version": "1.0.0-beta.0",
"repository": "emdaer/emdaer",
"homepage": "https://emdaer.github.io/",
"homepage": "https://emdaer.me/",
"keywords": [

@@ -13,10 +13,6 @@ "README"

"scripts": {
"write-docs": "emdaer && git add ./README.md",
"prepublish": "flow-remove-types -p src -d lib && npm run write-docs"
"prepublish": "flow-remove-types -p src -i .test.js -d lib"
},
"devDependencies": {
"flow-remove-types": "1.2.1"
},
"dependencies": {
"fs-extra": "3.0.1"
"js-yaml": "3.8.4"
},

@@ -23,0 +19,0 @@ "publishConfig": {

/* @flow */
import type { PluginCall, TransformCall } from './_types';
const { NO_CONTENT, NO_DESTINATION, NO_GENERATED } = require('./_errors');
const combineContent = require('./util/combineContent');
const addStamp = require('./util/addStamp');
const executePlugins = require('./util/executePlugins');
const applyTransforms = require('./util/applyTransforms');
const fs = require('fs-extra');
/**
* An instance of Emdaer corresponding to a document
*
* @param options
* @param {string|undefined} options.destination The path at which to write the document
* @param {Array<PluginCall>} options.content A list defining which plugins to call with what options
* @param {Array<TransformCall>} options.transforms A list defining which transforms to call with what options
*/
module.exports = class Emdaer {
destination: string;
content: Array<PluginCall>;
transforms: ?Array<TransformCall>;
generated: string;
constructor(options: {
destination?: string,
content?: Array<PluginCall>,
transforms?: Array<TransformCall>,
}) {
if (
typeof options.destination !== 'string' ||
!options.destination.length
) {
throw new Error(NO_DESTINATION);
}
if (!Array.isArray(options.content) || !options.content.length) {
throw new Error(NO_CONTENT);
}
Object.assign(this, {
destination: options.destination,
content: options.content,
transforms: (options && options.transforms) || null,
});
}
/**
* Generates the document
*
* @returns {Promise<string>} Resolves with the generated document
*/
async generate(): Promise<string> {
this.generated = await applyTransforms(
this.transforms,
combineContent(await executePlugins(this.content))
);
return this.generated;
}
/**
* Writes the document
*
* @returns {Promise<void>} Resolves when the document has been written
*/
async write(): Promise<void> {
if (!this.generated) {
throw new Error(NO_GENERATED);
}
return fs.outputFile(this.destination, this.generated);
}
module.exports = async function emdaer(origin: string, content: string) {
return addStamp(await applyTransforms(await executePlugins(content)), origin);
};
/* @flow */
import type { TransformCall } from '../_types';
const { safeLoad } = require('js-yaml');
const resolveTransform = require('../../src/util/resolveTransform');
const applyTransform = require('./applyTransform');
/**
* Applies provided transforms to generated content
* Applies transforms to generated content
*/
module.exports = async (
transforms: ?Array<TransformCall>,
module.exports = async function applyTransforms(
content: string
): Promise<string> => {
if (!transforms) {
return Promise.resolve(content);
}
return transforms.reduce(
async (
acc: Promise<string>,
[transform, options]: TransformCall
): Promise<string> => resolveTransform(transform)(await acc, options),
Promise.resolve(content)
);
): Promise<string> {
const replacementContent = content;
const matches = replacementContent.match(/<!--emdaer-t[\s\S]*?-->/g) || [];
return matches.reduce((acc, match): Promise<string> => {
const [, , body] = /(<!--emdaer-t)([\s\S]*?)(-->)/g.exec(match);
return (async () => {
const accContent = await acc;
return applyTransform(accContent, safeLoad(body));
})();
}, Promise.resolve(replacementContent));
};

@@ -8,3 +8,3 @@ /* @flow */

const executeNested = async (options: *) => {
async function executeNested(options: *): {} {
if (options && options.from) {

@@ -17,3 +17,3 @@ const [utilityPlugin, utilityOptions] = options.from;

return options;
};
}

@@ -23,5 +23,6 @@ /**

*/
const executePlugin = async ([plugin, options]: PluginCall): Promise<string> =>
resolvePlugin(plugin)(await executeNested(options));
async function executePlugin([plugin, options]: PluginCall): Promise<string> {
return (await resolvePlugin(plugin))(await executeNested(options));
}
module.exports = executePlugin;
/* @flow */
import type { PluginCall } from '../_types';
const { safeLoad } = require('js-yaml');

@@ -8,9 +8,17 @@ const executePlugin = require('./executePlugin');

/**
* Executes provided plugins to generate content
* Finds and executes plugins
*/
module.exports = async (content: Array<PluginCall>): Promise<Array<string>> =>
Promise.all(
content.map((pluginCall: PluginCall): Promise<string> =>
executePlugin(pluginCall)
)
);
module.exports = async function executePlugins(
content: string
): Promise<string> {
const replacementContent = content;
const matches = replacementContent.match(/<!--emdaer-p[\s\S]*?-->/g) || [];
return matches.reduce((acc, match): Promise<string> => {
const [comment, , body] = /(<!--emdaer-p)([\s\S]*?)(-->)/g.exec(match);
return (async () => {
const accContent = await acc;
return accContent.replace(comment, await executePlugin(safeLoad(body)));
})();
}, Promise.resolve(replacementContent));
};

@@ -10,5 +10,5 @@ /* @flow */

*/
module.exports = (pluginName: string): Plugin => {
module.exports = function resolvePlugin(pluginName: string): Plugin {
try {
return require(`@emdaer/plugin-${pluginName}`);
return require(pluginName);
} catch (error) {

@@ -15,0 +15,0 @@ throw new Error(`${NO_PLUGIN}: ${pluginName}`);

@@ -10,5 +10,5 @@ /* @flow */

*/
module.exports = (transformName: string): Transform => {
module.exports = function resolveTransform(transformName: string): Transform {
try {
return require(`@emdaer/transform-${transformName}`);
return require(transformName);
} catch (error) {

@@ -15,0 +15,0 @@ throw new Error(`${NO_TRANSFORM}: ${transformName}`);

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