Skip to content

Commit

Permalink
dynamic paths
Browse files Browse the repository at this point in the history
  • Loading branch information
mnater committed May 27, 2018
1 parent dd3100a commit db45fa3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 49 deletions.
52 changes: 3 additions & 49 deletions hyphenopoly.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,6 @@
* http://mnater.github.io/Hyphenopoly/LICENSE
*/

/*
* This is a basic (yet undocumented) Hyphenopoly-module for usage in node.js
* API will probably change and finally be documented in more detail.
*
* Please provide feedback on https://github.com/mnater/Hyphenopoly/issues
*
* ## Usage:
* 1. Configure Hyphenopoly with `Hyphenopoly.config`
* 2. Depending on how many languages are required:
* 1. If only one language is required, `Hyphenopoly.config` returns
* a promise for a hyphenateText-function for the specified language.
* 2. If more than one language is required, `Hyphenopoly.config` returns a
* map of promises
*
* ### Example
* ````javascript
* const Hyphenopoly = require("./hyphenopoly.module");
*
* const textHyphenators = Hyphenopoly.config({
* "require": ["de"],
* //for more than oe language: "require": ["de", "en-us"],
* "paths": {
* "maindir": "./",
* "patterndir": "./patterns/"
* },
* "hyphen": "•"
* });
*
* textHyphenators.then(
* //for more than oe language: textHyphenators.get("de").then(
* function ff(hyphenateText) {
* console.log(hyphenateText("Silbentrennung verbessert das Layout."));
* }
* );
* ````
*
* ### Performance
* On my machine with node.js 10.0.1:
*
* | module | setup | hyphenate 100 de words |
* | ------------- | -------------:| ----------------------:|
* | _hyphenopoly_ | _12ms_ | _2ms_ |
* | hyphen | 40ms | 370ms |
* | hypher | 70ms | 3ms |
*
*/

/* eslint-env node */
/* eslint no-console: 0 */
"use strict";
Expand Down Expand Up @@ -113,6 +66,7 @@ function loadWasm() {
`${H.c.paths.maindir}hyphenEngine.wasm`,
function cb(err, data) {
if (err) {
console.log(err);
H.events.dispatch("error", {"msg": `${H.c.paths.maindir}hyphenEngine.wasm not found.`});
} else {
H.binaries.hyphenEngine = new Uint8Array(data).buffer;
Expand Down Expand Up @@ -587,8 +541,8 @@ H.config = function config(userConfig) {
"normalize": setProp(false, 2),
"orphanControl": setProp(1, 2),
"paths": setProp(Object.create(null, {
"maindir": setProp("./", 2),
"patterndir": setProp("./patterns/", 2)
"maindir": setProp(`${__dirname}/`, 2),
"patterndir": setProp(`${__dirname}/patterns/`, 2)
}), 2),
"require": setProp([], 2),
"rightmin": setProp(0, 2)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"min/"
],
"browser": "Hyphenopoly_Loader.js",
"main": "hyphenopoly.module.js",
"repository": {
"type": "git",
"url": "https://github.com/mnater/Hyphenopoly"
Expand Down

0 comments on commit db45fa3

Please sign in to comment.