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

scigen

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scigen - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

lib/scigen.js

4

lib/cli.js

@@ -15,3 +15,3 @@ #!/usr/bin/env node

var _index = require("./index.js");
var _scigen = require("./scigen.js");

@@ -43,3 +43,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

var files = _objectSpread({}, (0, _index.scigen)(authors, bibinlatex).files, {
var files = _objectSpread({}, (0, _scigen.scigen)(authors, bibinlatex).files, {
'IEEEtran.cls': _fs["default"].readFileSync(_path["default"].resolve(__dirname, 'IEEEtran.cls')),

@@ -46,0 +46,0 @@ 'IEEE.bst': _fs["default"].readFileSync(_path["default"].resolve(__dirname, 'IEEE.bst'))

@@ -6,2 +6,8 @@ "use strict";

});
Object.defineProperty(exports, "scigen", {
enumerable: true,
get: function get() {
return _scigen.scigen;
}
});
Object.defineProperty(exports, "scigenSave", {

@@ -13,191 +19,5 @@ enumerable: true,

});
exports.scigen = void 0;
var _titleCase = require("title-case");
var _scigen = require("./scigen.mjs");
var _scirules = _interopRequireDefault(require("../rules/rules-compiled/scirules.json"));
var _system_names = _interopRequireDefault(require("../rules/rules-compiled/system_names.json"));
var _cli = require("./cli.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
var scigen = function scigen(authors, bibInLatex) {
var generate = function generate(rules, start) {
var rx = new RegExp('^(' + Object.keys(rules).sort(function (a, b) {
return b.length - a.length;
}).join('|') + ')');
var expand = function expand(key) {
var pick = function pick(array) {
return array[Math.floor(Math.random() * array.length)];
};
var plusRule = key.match(/(.*)[+]$/);
var sharpRule = key.match(/(.*)[#]$/);
if (plusRule) {
if (plusRule[1] in rules) {
rules[plusRule[1]] += 1;
} else {
rules[plusRule[1]] = 1;
}
return rules[plusRule[1]] - 1;
} else if (sharpRule) {
if (sharpRule[1] in rules) {
return Math.floor(Math.random() * (rules[sharpRule[1]] + 1));
} else {
return 0;
}
} else {
var process = function process(rule) {
var text = '';
for (var i in rule) {
var match = rule.substring(i).match(rx);
if (match) {
return text + expand(match[0]) + process(rule.slice(text.length + match[0].length));
} else {
text += rule[i];
}
}
return text;
};
return process(pick(rules[key]));
}
};
return {
text: prettyPrint(expand(start)),
rules: rules
};
};
var systemName = function systemName() {
var name = generate(_system_names["default"], 'SYSTEM_NAME').text;
var r = Math.random();
return r < 0.1 ? "{\\em ".concat(name, "}") : name.length <= 6 && r < 0.4 ? name.toUpperCase() : name;
};
var bibtex = function bibtex(rules, bibInLatex) {
return _toConsumableArray(Array(rules.CITATIONLABEL).keys()).map(function (label) {
return prettyPrint(generate(_objectSpread({}, _scirules["default"], {}, metadata, {
CITE_LABEL_GIVEN: [label.toString()]
}), bibInLatex ? 'BIB_IN_LATEX_ENTRY' : 'BIBTEX_ENTRY').text);
}).join('');
};
var makeFigures = function makeFigures(rules) {
var figures = {};
for (var _i = 0, _arr = _toConsumableArray(Array(rules.NEWFIGNUM).keys()); _i < _arr.length; _i++) {
var label = _arr[_i];
figures = _objectSpread({}, figures, _defineProperty({}, 'figure' + label + '.eps', ''));
}
for (var _i2 = 0, _arr2 = _toConsumableArray(Array(rules.NEWDIANUM).keys()); _i2 < _arr2.length; _i2++) {
var _label = _arr2[_i2];
figures = _objectSpread({}, figures, _defineProperty({}, 'dia' + _label + '.eps', ''));
}
return figures;
};
var prettyPrint = function prettyPrint(text) {
text = text.split('\n').map(function (line) {
line = line.trim();
line = line.replace(/ +/g, ' ');
line = line.replace(/\s+([.,?;:])/g, '$1');
line = line.replace(/\ba\s+([aeiou])/gi, '$1');
line = line.replace(/^\s*[a-z]/, function (l) {
return l.toUpperCase();
});
line = line.replace(/((([.:?!]\s+)|(=\s*\{\s*))[a-z])/g, function (l) {
return l.toUpperCase();
});
line = line.replace(/\W((jan)|(feb)|(mar)|(apr)|(jun)|(jul)|(aug)|(sep)|(oct)|(nov)|(dec))\s/gi, function (l) {
return l[0].toUpperCase() + l.substring(1, l.length) + '. ';
});
line = line.replace(/\\Em /g, '\\em');
var title = line.match(/(\\(((sub)?section)|(slideheading)|(title))\*?)\{(.*)\}/);
if (title) {
line = title[1] + '{' + (0, _titleCase.titleCase)(title[7]) + '}';
}
if (line.match(/\n$/)) {
line += '\n';
}
return line;
}).join('\n');
return text;
};
authors = authors || [generate(_scirules["default"], 'SCI_SOURCE').text].concat(_toConsumableArray(Math.random() > 0.5 ? [generate(_scirules["default"], 'SCI_SOURCE').text] : []), _toConsumableArray(Math.random() > 0.5 ? [generate(_scirules["default"], 'SCI_SOURCE').text] : []), _toConsumableArray(Math.random() > 0.5 ? [generate(_scirules["default"], 'SCI_SOURCE').text] : []));
var metadata = {
SYSNAME: [systemName()],
AUTHOR_NAME: authors,
SCIAUTHORS: [authors.slice(0, -1).join(', ') + (authors.length > 1 ? ' and ' : '') + authors[authors.length - 1]],
SCI_SOURCE: [].concat(_toConsumableArray(_scirules["default"].SCI_SOURCE), _toConsumableArray(authors.flatMap(function (l, i, a) {
return Array((a.length - i) * 5).fill(l);
})))
};
var _generate = generate(_objectSpread({}, _scirules["default"], {}, metadata), 'SCIPAPER_LATEX'),
text = _generate.text,
rules = _generate.rules;
return {
files: _objectSpread({
'paper.tex': bibInLatex ? text.replace( // replace citations by plain Latex
/\\cite\{((cite:\d+(, )?)+)\}/g, function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return '[' + args[1].split(', ').map(function (c) {
return parseInt(c.replace(/cite:/, '')) + 1;
}).join(', ') + ']';
}).replace( // replace references to figures / diagrams by plain Latex
/\\ref\{([a-z0-9:,]+)\}/g, function () {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return parseInt(args[1].replace(/((fig)|(dia)):label/, '')) + 1;
}).replace( // create bibliography in plain Latex
/\\bibliography\{scigenbibfile\}\n\\bibliographystyle\{((acm)|(IEEE))\}/, '\\section*{References}\n' + '\\renewcommand\\labelenumi{[\\theenumi]}\n' + '\\begin{enumerate}\n' + bibtex(rules, true).replace(/\\textsc\{([^{}]*)\}\. /g, function (match, authors) {
authors = authors.split(' and ').map(function (author) {
author = author.split(' ');
return author[author.length - 1] + ', ' + author.slice(0, -1).map(function (fName) {
return fName[0] + '.';
}).join(' ');
});
return '\\textsc{' + authors.slice(0, -1).join(', ') + (authors.length >= 3 ? ',' : '') + (authors.length >= 2 ? ' and ' : '') + authors[authors.length - 1] + '} ';
}) + '\\end{enumerate}') : text,
'scigenbibfile.bib': bibtex(rules, false)
}, makeFigures(rules))
};
};
exports.scigen = scigen;
var _cli = require("./cli.mjs");
{
"name": "scigen",
"version": "0.1.1",
"version": "0.1.2",
"description": "Create scientific papers on the fly: SciGen brought to the browser and to Node.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -62,5 +62,5 @@ ![# SciGen.js](logo.png)

- Rendering diagrams and figures requires _Ghostscript_ in the [original SciGen project](https://github.com/strib/scigen). _Ghostscript_ is not available for the browser. A workaround would probably involve rewriting the original EPS rules in some format which is supported by _TexLive.js_ (maybe SVG or TIKZ). As this module is aimed at the browser, the diagram and figure code production is not yet implemented in the JavaScript code. For locally producing TEX and PDF files with figures and diagrams, use the [original SciGen project](https://github.com/strib/scigen) with [this unmerged fix](https://github.com/strib/scigen/pull/5).
- Works in Firefox but not in Chromium.
- Works in Firefox Desktop & Mobile and in Chrome Mobile, but not in Chrome/Chromium Desktop. Cf. [this issue with TexLive.js](https://github.com/manuels/texlive.js/issues/63).
### Motivation
The server-side code at the [original SciGen website](https://pdos.csail.mit.edu/archive/scigen/) appears to be broken. The aim of this project is therefore to provide a more server-independent implementation.
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