initial commit
This commit is contained in:
commit
6aa3c9a604
17 changed files with 12072 additions and 0 deletions
13
.eslintrc.json
Normal file
13
.eslintrc.json
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"browser": true,
|
||||||
|
"es2021": true
|
||||||
|
},
|
||||||
|
"extends": "standard-with-typescript",
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": "latest",
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
}
|
||||||
|
}
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
node_modules
|
36
.vscode/launch.json
vendored
Normal file
36
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
{
|
||||||
|
// 使用 IntelliSense 以得知可用的屬性。
|
||||||
|
// 暫留以檢視現有屬性的描述。
|
||||||
|
// 如需詳細資訊,請瀏覽: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "啟動程式",
|
||||||
|
"skipFiles": [
|
||||||
|
"<node_internals>/**"
|
||||||
|
],
|
||||||
|
"program": "${workspaceFolder}/src/index.ts",
|
||||||
|
"outFiles": [
|
||||||
|
"${workspaceFolder}/**/*.js"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Mocha Current Test",
|
||||||
|
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
|
||||||
|
"args": [
|
||||||
|
"--no-timeouts",
|
||||||
|
"--colors",
|
||||||
|
"${file}",
|
||||||
|
"--require",
|
||||||
|
"ts-node/register"
|
||||||
|
],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"sourceMaps": true,
|
||||||
|
"internalConsoleOptions": "neverOpen"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
22
3rdparty/harfbuzzjs/LICENSE
vendored
Normal file
22
3rdparty/harfbuzzjs/LICENSE
vendored
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
Apache license for Zephyr libc implementations (zephyr-string.c),
|
||||||
|
emmalloc.cpp (from emscripten project) and MIT for rest of the project
|
||||||
|
|
||||||
|
Copyright (c) 2019 Ebrahim Byagowi
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
BIN
3rdparty/harfbuzzjs/hb.wasm
vendored
Executable file
BIN
3rdparty/harfbuzzjs/hb.wasm
vendored
Executable file
Binary file not shown.
11481
package-lock.json
generated
Normal file
11481
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
45
package.json
Normal file
45
package.json
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
{
|
||||||
|
"name": "clo",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "a little typesetting engine in TypeScript",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/Yoxem/clo.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"typesetting"
|
||||||
|
],
|
||||||
|
"author": "Tan Kian-ting",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/Yoxem/clo/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/Yoxem/clo#readme",
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/chai": "^4.3.5",
|
||||||
|
"@types/mocha": "^10.0.1",
|
||||||
|
"@types/node": "^20.5.7",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^6.5.0",
|
||||||
|
"chai": "^4.3.8",
|
||||||
|
"eslint": "^8.48.0",
|
||||||
|
"eslint-config-standard-with-typescript": "^39.0.0",
|
||||||
|
"eslint-plugin-import": "^2.28.1",
|
||||||
|
"eslint-plugin-n": "^16.0.2",
|
||||||
|
"eslint-plugin-promise": "^6.1.1",
|
||||||
|
"mocha": "^10.2.0",
|
||||||
|
"nyc": "^15.1.0",
|
||||||
|
"ts-node": "^10.9.1",
|
||||||
|
"tslint": "^6.1.3",
|
||||||
|
"typescript": "^5.2.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@pdf-lib/fontkit": "^1.1.1",
|
||||||
|
"harfbuzzjs": "^0.3.3",
|
||||||
|
"npx": "^3.0.0",
|
||||||
|
"pdf-lib": "^1.17.1"
|
||||||
|
}
|
||||||
|
}
|
43
src/harfbuzz.js
Normal file
43
src/harfbuzz.js
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.harfbuzzTest = void 0;
|
||||||
|
var hb = require('harfbuzzjs/hbjs');
|
||||||
|
var fs = require('fs');
|
||||||
|
function harfbuzzTest(inputString) {
|
||||||
|
WebAssembly.instantiate(fs.readFileSync(__dirname + "/../3rdparty/harfbuzzjs/hb.wasm"))
|
||||||
|
.then(function (wsm) {
|
||||||
|
hb = hb(wsm.instance);
|
||||||
|
let fontdata = fs.readFileSync("/usr/share/fonts/truetype/freefont/FreeSerif.ttf");
|
||||||
|
//hbjs(fontdata.instance);
|
||||||
|
//console.log(a);
|
||||||
|
var blob = hb.createBlob(fontdata); // Load the font data into something Harfbuzz can use
|
||||||
|
var face = hb.createFace(blob, 0); // Select the first font in the file (there's normally only one!)
|
||||||
|
var font = hb.createFont(face); // Create a Harfbuzz font object from the face
|
||||||
|
var buffer = hb.createBuffer(); // Make a buffer to hold some text
|
||||||
|
buffer.addText(inputString); // Fill it with some stuff
|
||||||
|
buffer.guessSegmentProperties(); // Set script, language and direction
|
||||||
|
hb.shape(font, buffer); // Shape the text, determining glyph IDs and positions
|
||||||
|
var output = buffer.json();
|
||||||
|
// Enumerate the glyphs
|
||||||
|
console.log("id\tax\tdx\tdy");
|
||||||
|
var xCursor = 0;
|
||||||
|
var yCursor = 0;
|
||||||
|
for (var glyph of output) {
|
||||||
|
var glyphId = glyph.g;
|
||||||
|
var xAdvance = glyph.ax;
|
||||||
|
var xDisplacement = glyph.dx;
|
||||||
|
var yDisplacement = glyph.dy;
|
||||||
|
var svgPath = font.glyphToPath(glyphId);
|
||||||
|
console.log(glyphId + "\t" + xAdvance + "\t" + xDisplacement + "\t" + yDisplacement);
|
||||||
|
// You need to supply this bit
|
||||||
|
//drawAGlyph(svgPath, xCursor + xDisplacement, yDisplacement);
|
||||||
|
// xCursor += xAdvance;
|
||||||
|
}
|
||||||
|
// Release memory
|
||||||
|
buffer.destroy();
|
||||||
|
font.destroy();
|
||||||
|
face.destroy();
|
||||||
|
blob.destroy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.harfbuzzTest = harfbuzzTest;
|
56
src/harfbuzz.ts
Normal file
56
src/harfbuzz.ts
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
var hb = require('harfbuzzjs/hbjs');
|
||||||
|
var fs = require('fs');
|
||||||
|
|
||||||
|
export function harfbuzzTest(inputString: string){
|
||||||
|
WebAssembly.instantiate(fs.readFileSync(__dirname+"/../3rdparty/harfbuzzjs/hb.wasm"))
|
||||||
|
.then(function (wsm) {
|
||||||
|
|
||||||
|
hb = hb(wsm.instance);
|
||||||
|
|
||||||
|
|
||||||
|
let fontdata = fs.readFileSync("/usr/share/fonts/truetype/freefont/FreeSerif.ttf");
|
||||||
|
|
||||||
|
//hbjs(fontdata.instance);
|
||||||
|
|
||||||
|
//console.log(a);
|
||||||
|
|
||||||
|
var blob = hb.createBlob(fontdata); // Load the font data into something Harfbuzz can use
|
||||||
|
var face = hb.createFace(blob, 0); // Select the first font in the file (there's normally only one!)
|
||||||
|
var font = hb.createFont(face); // Create a Harfbuzz font object from the face
|
||||||
|
var buffer = hb.createBuffer(); // Make a buffer to hold some text
|
||||||
|
buffer.addText(inputString); // Fill it with some stuff
|
||||||
|
buffer.guessSegmentProperties(); // Set script, language and direction
|
||||||
|
hb.shape(font, buffer); // Shape the text, determining glyph IDs and positions
|
||||||
|
var output : Array<{g : number,
|
||||||
|
ax : number,
|
||||||
|
dx : number,
|
||||||
|
dy : number}> = buffer.json();
|
||||||
|
|
||||||
|
// Enumerate the glyphs
|
||||||
|
console.log("id\tax\tdx\tdy");
|
||||||
|
|
||||||
|
var xCursor = 0;
|
||||||
|
var yCursor = 0;
|
||||||
|
for (var glyph of output) {
|
||||||
|
var glyphId = glyph.g;
|
||||||
|
var xAdvance = glyph.ax;
|
||||||
|
var xDisplacement = glyph.dx;
|
||||||
|
var yDisplacement = glyph.dy;
|
||||||
|
|
||||||
|
var svgPath = font.glyphToPath(glyphId);
|
||||||
|
|
||||||
|
console.log(glyphId + "\t" + xAdvance + "\t" + xDisplacement + "\t" + yDisplacement);
|
||||||
|
|
||||||
|
// You need to supply this bit
|
||||||
|
//drawAGlyph(svgPath, xCursor + xDisplacement, yDisplacement);
|
||||||
|
|
||||||
|
// xCursor += xAdvance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release memory
|
||||||
|
buffer.destroy();
|
||||||
|
font.destroy();
|
||||||
|
face.destroy();
|
||||||
|
blob.destroy();
|
||||||
|
});
|
||||||
|
}
|
57
src/index.js
Normal file
57
src/index.js
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.thenDo = exports.charToCodepoint = exports.match1Char = void 0;
|
||||||
|
var fs = require('fs');
|
||||||
|
/**
|
||||||
|
* @description
|
||||||
|
* it returns a function which test if the first char of the `remained` part of
|
||||||
|
* the argument of the function is `c`, if it's true, update the `MatchedPair` wrapped
|
||||||
|
* in `Some`. Otherwise, it returns `None`.
|
||||||
|
* * @param c : the char to be test.
|
||||||
|
* @returns the updated `MatchedPair` wrapped in `Some(x)` or `None`.
|
||||||
|
*/
|
||||||
|
function match1Char(c) {
|
||||||
|
return (m) => {
|
||||||
|
const charToBeMatched = m.remained[0];
|
||||||
|
if (charToBeMatched === c) {
|
||||||
|
return { _tag: "Some", value: {
|
||||||
|
matched: m.matched + charToBeMatched,
|
||||||
|
remained: m.remained.substring(1)
|
||||||
|
} };
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return { _tag: "None" };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
exports.match1Char = match1Char;
|
||||||
|
;
|
||||||
|
/**
|
||||||
|
* convert the one-char string to codepoint.
|
||||||
|
* @param s : the string to code point.
|
||||||
|
* @returns if `s.length > 1` return error; otherwise, return the codepoint of `s`.
|
||||||
|
*/
|
||||||
|
function charToCodepoint(s) {
|
||||||
|
if (s.length > 1) {
|
||||||
|
throw new Error("Error: the length of input string for " + s + "is " + s.length + `,
|
||||||
|
however, it should be 1.`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return s.charCodeAt(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.charToCodepoint = charToCodepoint;
|
||||||
|
/**
|
||||||
|
* @description thendo(input, f, ...) like
|
||||||
|
* a ==> f
|
||||||
|
*/
|
||||||
|
function thenDo(input, f) {
|
||||||
|
if (input._tag == "None") {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let inner = input.value;
|
||||||
|
return f(inner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.thenDo = thenDo;
|
74
src/index.ts
Normal file
74
src/index.ts
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
var fs = require('fs');
|
||||||
|
|
||||||
|
type Some<T> = { _tag: "Some"; value: T };
|
||||||
|
type None = {_tag: "None"};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Like the `Some(a)` and `None` in Rust.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```ts
|
||||||
|
* let exam1 : Maybe<Number> = { _tag: "Some", value: 12 };
|
||||||
|
* let exam2 : Maybe<Number> = None;
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export type Maybe<T> = Some<T> | None;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description
|
||||||
|
* the pair of the string to be matched later and the string that have been matched
|
||||||
|
* @param matched : string have been matched
|
||||||
|
* @param remained : string will be tested whether it'll be matched.
|
||||||
|
*/
|
||||||
|
export type MatcheePair = {matched : string; remained : string};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description
|
||||||
|
* it returns a function which test if the first char of the `remained` part of
|
||||||
|
* the argument of the function is `c`, if it's true, update the `MatchedPair` wrapped
|
||||||
|
* in `Some`. Otherwise, it returns `None`.
|
||||||
|
* * @param c : the char to be test.
|
||||||
|
* @returns the updated `MatchedPair` wrapped in `Some(x)` or `None`.
|
||||||
|
*/
|
||||||
|
export function match1Char(c : string) : (m: MatcheePair) => Maybe<MatcheePair> {
|
||||||
|
return (m : MatcheePair)=>{
|
||||||
|
const charToBeMatched = m.remained[0];
|
||||||
|
if (charToBeMatched === c){
|
||||||
|
return {_tag: "Some", value :{
|
||||||
|
matched : m.matched + charToBeMatched,
|
||||||
|
remained : m.remained.substring(1)}};
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return {_tag: "None"};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert the one-char string to codepoint.
|
||||||
|
* @param s : the string to code point.
|
||||||
|
* @returns if `s.length > 1` return error; otherwise, return the codepoint of `s`.
|
||||||
|
*/
|
||||||
|
export function charToCodepoint(s : string): number{
|
||||||
|
if (s.length > 1){
|
||||||
|
throw new Error("Error: the length of input string for "+s+ "is "+s.length+`,
|
||||||
|
however, it should be 1.`);
|
||||||
|
}else{
|
||||||
|
return s.charCodeAt(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description thendo(input, f, ...) like
|
||||||
|
* a ==> f
|
||||||
|
*/
|
||||||
|
export function thenDo<T>(input : Maybe<T>, f : Function) : Maybe<T>{
|
||||||
|
if (input._tag == "None"){
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
let inner = input.value;
|
||||||
|
return f(inner);
|
||||||
|
}
|
||||||
|
}
|
32
src/pdfManipulate.js
Normal file
32
src/pdfManipulate.js
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
"use strict";
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.pdfGenerate = void 0;
|
||||||
|
const fs_1 = require("fs");
|
||||||
|
const pdf_lib_1 = require("pdf-lib");
|
||||||
|
var fontkit = require('@pdf-lib/fontkit');
|
||||||
|
function pdfGenerate() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const pdfDoc = yield pdf_lib_1.PDFDocument.create();
|
||||||
|
const page = pdfDoc.addPage();
|
||||||
|
pdfDoc.registerFontkit(fontkit);
|
||||||
|
const fontBytes = (0, fs_1.readFileSync)("/usr/share/fonts/uming.ttf");
|
||||||
|
const font2 = yield pdfDoc.embedFont(fontBytes, { subset: true });
|
||||||
|
const fontBytes2 = (0, fs_1.readFileSync)("/usr/share/fonts/truetype/noto/NotoSansArabic-Light.ttf");
|
||||||
|
const font3 = yield pdfDoc.embedFont(fontBytes2, { subset: true });
|
||||||
|
page.drawText("x=20, y=20", { x: 20, y: 20 });
|
||||||
|
page.drawText("x:20, y:100 天地人", { x: 20, y: 100, font: font2 });
|
||||||
|
page.drawText("عربي", { x: 50, y: 150, font: font3 });
|
||||||
|
const pdfBytes = yield pdfDoc.save();
|
||||||
|
(0, fs_1.writeFileSync)('/tmp/test.pdf', pdfBytes);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.pdfGenerate = pdfGenerate;
|
25
src/pdfManipulate.ts
Normal file
25
src/pdfManipulate.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import { readFileSync, writeFileSync } from "fs";
|
||||||
|
import { PDFDocument } from "pdf-lib";
|
||||||
|
var fontkit = require('@pdf-lib/fontkit');
|
||||||
|
|
||||||
|
export async function pdfGenerate(){
|
||||||
|
|
||||||
|
const pdfDoc = await PDFDocument.create()
|
||||||
|
const page = pdfDoc.addPage()
|
||||||
|
|
||||||
|
pdfDoc.registerFontkit(fontkit);
|
||||||
|
const fontBytes = readFileSync("/usr/share/fonts/uming.ttf");
|
||||||
|
const font2 = await pdfDoc.embedFont(fontBytes, {subset:true})
|
||||||
|
|
||||||
|
const fontBytes2 = readFileSync("/usr/share/fonts/truetype/noto/NotoSansArabic-Light.ttf")
|
||||||
|
|
||||||
|
const font3 = await pdfDoc.embedFont(fontBytes2, {subset:true})
|
||||||
|
|
||||||
|
page.drawText("x=20, y=20", {x : 20, y : 20})
|
||||||
|
page.drawText("x:20, y:100 天地人", {x : 20, y : 100, font: font2})
|
||||||
|
page.drawText("عربي", {x : 50, y : 150, font: font3})
|
||||||
|
|
||||||
|
const pdfBytes = await pdfDoc.save();
|
||||||
|
|
||||||
|
writeFileSync('/tmp/test.pdf', pdfBytes);
|
||||||
|
}
|
28
tests/index.js
Normal file
28
tests/index.js
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
var assert = require("assert");
|
||||||
|
var cloMain = require("../src");
|
||||||
|
var a = cloMain.match1Char("我");
|
||||||
|
var example1 = a({ matched: "", remained: "我的" });
|
||||||
|
assert(example1._tag == "Some");
|
||||||
|
assert(example1.value.matched == "我");
|
||||||
|
assert(example1.value.remained == "的");
|
||||||
|
var example2 = a({ matched: "", remained: "妳的" });
|
||||||
|
assert(example2._tag == "None");
|
||||||
|
var thenDo = cloMain.thenDo;
|
||||||
|
// composed part x
|
||||||
|
var compPart1 = cloMain.match1Char("我");
|
||||||
|
var compPart2 = cloMain.match1Char("的");
|
||||||
|
var doThenTestee1 = { _tag: "Some", value: { matched: "", remained: "我的貓" } };
|
||||||
|
var doTestRes1 = thenDo(thenDo(doThenTestee1, compPart1), compPart2);
|
||||||
|
assert(doTestRes1._tag == "Some");
|
||||||
|
assert(doTestRes1.value.matched == "我的");
|
||||||
|
assert(doTestRes1.value.remained == "貓");
|
||||||
|
var doThenTestee2 = { _tag: "Some", value: { matched: "", remained: "我們" } };
|
||||||
|
var doTestRes2 = thenDo(thenDo(doThenTestee2, compPart1), compPart2);
|
||||||
|
assert(doTestRes2._tag == "None");
|
||||||
|
// harfbuzz test
|
||||||
|
var harfbuzz = require("../src/harfbuzz.js");
|
||||||
|
harfbuzz.harfbuzzTest("123.abc");
|
||||||
|
// pdf test
|
||||||
|
var pdfManipulate = require("../src/pdfManipulate.js");
|
||||||
|
pdfManipulate.pdfGenerate("123.abc");
|
||||||
|
console.log("/tmp/test.pdf產出ah");
|
41
tests/index.ts
Normal file
41
tests/index.ts
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
let assert = require("assert");
|
||||||
|
let cloMain = require("../src");
|
||||||
|
|
||||||
|
let a = cloMain.match1Char("我");
|
||||||
|
|
||||||
|
let example1 = a({matched: "", remained: "我的"});
|
||||||
|
assert(example1._tag == "Some");
|
||||||
|
assert(example1.value.matched == "我");
|
||||||
|
assert(example1.value.remained == "的");
|
||||||
|
|
||||||
|
let example2 = a({matched: "", remained: "妳的"});
|
||||||
|
assert(example2._tag == "None");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let thenDo = cloMain.thenDo;
|
||||||
|
// composed part x
|
||||||
|
let compPart1 = cloMain.match1Char("我");
|
||||||
|
let compPart2 = cloMain.match1Char("的");
|
||||||
|
|
||||||
|
let doThenTestee1 = {_tag : "Some",value : {matched: "", remained: "我的貓"}};
|
||||||
|
let doTestRes1 = thenDo(thenDo(doThenTestee1, compPart1), compPart2);
|
||||||
|
assert(doTestRes1._tag == "Some");
|
||||||
|
assert(doTestRes1.value.matched == "我的");
|
||||||
|
assert(doTestRes1.value.remained == "貓");
|
||||||
|
|
||||||
|
|
||||||
|
let doThenTestee2 = {_tag : "Some",value : {matched: "", remained: "我們"}};
|
||||||
|
let doTestRes2 = thenDo(thenDo(doThenTestee2, compPart1), compPart2);
|
||||||
|
assert(doTestRes2._tag == "None");
|
||||||
|
|
||||||
|
|
||||||
|
// harfbuzz test
|
||||||
|
let harfbuzz = require("../src/harfbuzz.js");
|
||||||
|
harfbuzz.harfbuzzTest("123.abc");
|
||||||
|
|
||||||
|
// pdf test
|
||||||
|
let pdfManipulate = require("../src/pdfManipulate.js");
|
||||||
|
pdfManipulate.pdfGenerate("123.abc");
|
||||||
|
console.log("/tmp/test.pdf產出ah");
|
||||||
|
|
109
tsconfig.json
Normal file
109
tsconfig.json
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
/* Visit https://aka.ms/tsconfig to read more about this file */
|
||||||
|
|
||||||
|
/* Projects */
|
||||||
|
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
||||||
|
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
||||||
|
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
||||||
|
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
||||||
|
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
||||||
|
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||||
|
|
||||||
|
/* Language and Environment */
|
||||||
|
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||||
|
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||||
|
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||||
|
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
||||||
|
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||||
|
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
||||||
|
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
||||||
|
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
||||||
|
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
||||||
|
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
||||||
|
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||||
|
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||||
|
|
||||||
|
/* Modules */
|
||||||
|
"module": "commonjs", /* Specify what module code is generated. */
|
||||||
|
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||||
|
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||||
|
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||||
|
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||||
|
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||||
|
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
||||||
|
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
||||||
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||||
|
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
||||||
|
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
||||||
|
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
||||||
|
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
||||||
|
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
||||||
|
// "resolveJsonModule": true, /* Enable importing .json files. */
|
||||||
|
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
||||||
|
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
||||||
|
|
||||||
|
/* JavaScript Support */
|
||||||
|
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
||||||
|
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||||
|
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
||||||
|
|
||||||
|
/* Emit */
|
||||||
|
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||||
|
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||||
|
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||||
|
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||||
|
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||||
|
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||||
|
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
||||||
|
// "removeComments": true, /* Disable emitting comments. */
|
||||||
|
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||||
|
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||||
|
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
||||||
|
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
||||||
|
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
||||||
|
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||||
|
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
||||||
|
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
||||||
|
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
||||||
|
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
||||||
|
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
||||||
|
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||||
|
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
||||||
|
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
||||||
|
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
||||||
|
|
||||||
|
/* Interop Constraints */
|
||||||
|
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||||
|
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
||||||
|
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||||
|
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
||||||
|
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||||
|
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||||
|
|
||||||
|
/* Type Checking */
|
||||||
|
"strict": true, /* Enable all strict type-checking options. */
|
||||||
|
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
||||||
|
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
||||||
|
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||||
|
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
||||||
|
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
||||||
|
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
||||||
|
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
||||||
|
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
||||||
|
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
||||||
|
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
||||||
|
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
||||||
|
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
||||||
|
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
||||||
|
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
||||||
|
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
||||||
|
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
||||||
|
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
||||||
|
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
||||||
|
|
||||||
|
/* Completeness */
|
||||||
|
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||||
|
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||||
|
}
|
||||||
|
}
|
9
tslint.json
Normal file
9
tslint.json
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"defaultSeverity": "error",
|
||||||
|
"extends": [
|
||||||
|
"tslint:recommended"
|
||||||
|
],
|
||||||
|
"jsRules": {},
|
||||||
|
"rules": {},
|
||||||
|
"rulesDirectory": []
|
||||||
|
}
|
Loading…
Reference in a new issue