Skip to content

Commit

Permalink
[npm publish] - npm publish 2020.3.17
Browse files Browse the repository at this point in the history
- add modal-support to function window.domOnEventAjaxProgressUpdate
- update shell-function shRawLibFetch to accept footer after file-none
- un-rename errDefault to errorDefault
- remove function errorMessagePrepend
- rename message to msg
- rename text to str
- update shell-function shRawLibFetch to apply diff
- add function promisify
- update function httpFetch with abort-handling
- update function shRawLibFetch to inline-fetch resources to raw.xxx.js
- add function httpFetch using fetch-api and promises
- remove polyfills Array.p.flat, Array.p.flatMap, TextDecoder, TextEncoder
- add workaround for nodejs v12 bug - libuv/libuv#2587
- add function stringLineCount
- simplify globalThis polyfill
  • Loading branch information
kaizhu256 committed Mar 17, 2020
1 parent 493388b commit 7a9661c
Show file tree
Hide file tree
Showing 14 changed files with 2,531 additions and 4,263 deletions.
370 changes: 133 additions & 237 deletions README.md

Large diffs are not rendered by default.

256 changes: 54 additions & 202 deletions lib.apidoc.js

Large diffs are not rendered by default.

214 changes: 33 additions & 181 deletions lib.github_crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
/* jslint utility2:true */
(function (globalThis) {
"use strict";
let ArrayPrototypeFlat;
let TextXxcoder;
let consoleError;
let debugName;
let local;
Expand All @@ -36,156 +34,12 @@
return argList[0];
};
}
// polyfill
ArrayPrototypeFlat = function (depth) {
/*
* this function will polyfill Array.prototype.flat
* https://github.com/jonathantneal/array-flat-polyfill
*/
depth = (
globalThis.isNaN(depth)
? 1
: Number(depth)
);
if (!depth) {
return Array.prototype.slice.call(this);
}
return Array.prototype.reduce.call(this, function (acc, cur) {
if (Array.isArray(cur)) {
// recurse
acc.push.apply(acc, ArrayPrototypeFlat.call(cur, depth - 1));
} else {
acc.push(cur);
}
return acc;
}, []);
};
Array.prototype.flat = Array.prototype.flat || ArrayPrototypeFlat;
Array.prototype.flatMap = Array.prototype.flatMap || function flatMap(
...argList
) {
/*
* this function will polyfill Array.prototype.flatMap
* https://github.com/jonathantneal/array-flat-polyfill
*/
return this.map(...argList).flat();
};
String.prototype.trimEnd = (
String.prototype.trimEnd || String.prototype.trimRight
);
String.prototype.trimStart = (
String.prototype.trimStart || String.prototype.trimLeft
);
(function () {
try {
globalThis.TextDecoder = (
globalThis.TextDecoder || require("util").TextDecoder
);
globalThis.TextEncoder = (
globalThis.TextEncoder || require("util").TextEncoder
);
} catch (ignore) {}
}());
TextXxcoder = function () {
/*
* this function will polyfill TextDecoder/TextEncoder
* https://gist.github.com/Yaffle/5458286
*/
return;
};
TextXxcoder.prototype.decode = function (octets) {
/*
* this function will polyfill TextDecoder.prototype.decode
* https://gist.github.com/Yaffle/5458286
*/
let bytesNeeded;
let codePoint;
let ii;
let kk;
let octet;
let string;
string = "";
ii = 0;
while (ii < octets.length) {
octet = octets[ii];
bytesNeeded = 0;
codePoint = 0;
if (octet <= 0x7F) {
bytesNeeded = 0;
codePoint = octet & 0xFF;
} else if (octet <= 0xDF) {
bytesNeeded = 1;
codePoint = octet & 0x1F;
} else if (octet <= 0xEF) {
bytesNeeded = 2;
codePoint = octet & 0x0F;
} else if (octet <= 0xF4) {
bytesNeeded = 3;
codePoint = octet & 0x07;
}
if (octets.length - ii - bytesNeeded > 0) {
kk = 0;
while (kk < bytesNeeded) {
octet = octets[ii + kk + 1];
codePoint = (codePoint << 6) | (octet & 0x3F);
kk += 1;
}
} else {
codePoint = 0xFFFD;
bytesNeeded = octets.length - ii;
}
string += String.fromCodePoint(codePoint);
ii += bytesNeeded + 1;
}
return string;
};
TextXxcoder.prototype.encode = function (string) {
/*
* this function will polyfill TextEncoder.prototype.encode
* https://gist.github.com/Yaffle/5458286
*/
let bits;
let cc;
let codePoint;
let ii;
let length;
let octets;
octets = [];
length = string.length;
ii = 0;
while (ii < length) {
codePoint = string.codePointAt(ii);
cc = 0;
bits = 0;
if (codePoint <= 0x0000007F) {
cc = 0;
bits = 0x00;
} else if (codePoint <= 0x000007FF) {
cc = 6;
bits = 0xC0;
} else if (codePoint <= 0x0000FFFF) {
cc = 12;
bits = 0xE0;
} else if (codePoint <= 0x001FFFFF) {
cc = 18;
bits = 0xF0;
}
octets.push(bits | (codePoint >> cc));
cc -= 6;
while (cc >= 0) {
octets.push(0x80 | ((codePoint >> cc) & 0x3F));
cc -= 6;
}
ii += (
codePoint >= 0x10000
? 2
: 1
);
}
return octets;
};
globalThis.TextDecoder = globalThis.TextDecoder || TextXxcoder;
globalThis.TextEncoder = globalThis.TextEncoder || TextXxcoder;
// init local
local = {};
local.local = local;
Expand All @@ -198,34 +52,32 @@
);
// init isWebWorker
local.isWebWorker = (
local.isBrowser && typeof globalThis.importScript === "function"
local.isBrowser && typeof globalThis.importScripts === "function"
);
// init function
local.assertOrThrow = function (passed, message) {
local.assertOrThrow = function (passed, msg) {
/*
* this function will throw err.<message> if <passed> is falsy
* this function will throw err.<msg> if <passed> is falsy
*/
let err;
if (passed) {
return;
}
err = (
throw (
(
message
&& typeof message.message === "string"
&& typeof message.stack === "string"
msg
&& typeof msg.message === "string"
&& typeof msg.stack === "string"
)
// if message is errObj, then leave as is
? message
// if msg is err, then leave as is
? msg
: new Error(
typeof message === "string"
// if message is a string, then leave as is
? message
// else JSON.stringify message
: JSON.stringify(message, undefined, 4)
typeof msg === "string"
// if msg is a string, then leave as is
? msg
// else JSON.stringify msg
: JSON.stringify(msg, undefined, 4)
)
);
throw err;
};
local.coalesce = function (...argList) {
/*
Expand All @@ -248,6 +100,7 @@
* this function will sync "rm -rf" <dir>
*/
let child_process;
// do nothing if module does not exist
try {
child_process = require("child_process");
} catch (ignore) {
Expand All @@ -266,6 +119,7 @@
* this function will sync write <data> to <file> with "mkdir -p"
*/
let fs;
// do nothing if module does not exist
try {
fs = require("fs");
} catch (ignore) {
Expand Down Expand Up @@ -378,9 +232,7 @@
local.vm = require("vm");
local.zlib = require("zlib");
}
}((typeof globalThis === "object" && globalThis) || (function () {
return Function("return this")(); // jslint ignore:line
}())));
}((typeof globalThis === "object" && globalThis) || window));
// assets.utility2.header.js - end


Expand Down Expand Up @@ -418,7 +270,7 @@ local.ajax = function (opt, onError) {
* this function will send an ajax-req
* with given <opt>.url and callback <onError>
* with err and timeout handling
* example usage:
* example use:
local.ajax({
data: "hello world",
header: {"x-header-hello": "world"},
Expand Down Expand Up @@ -607,7 +459,7 @@ local.ajax = function (opt, onError) {
/*
* this function will init xhr
*/
// init opt
// init <opt>
Object.keys(opt).forEach(function (key) {
if (key[0] !== "_") {
xhr[key] = opt[key];
Expand Down Expand Up @@ -770,7 +622,7 @@ local.ajax = function (opt, onError) {

local.cliRun = function (opt) {
/*
* this function will run the cli with given <opt>
* this function will run cli with given <opt>
*/
local.cliDict._eval = local.cliDict._eval || function () {
/*
Expand All @@ -788,8 +640,8 @@ local.cliRun = function (opt) {
let commandList;
let file;
let packageJson;
let text;
let textDict;
let str;
let strDict;
commandList = [
{
argList: "<arg2> ...",
Expand All @@ -814,23 +666,23 @@ local.cliRun = function (opt) {
opt.rgxComment = opt.rgxComment || (
/\)\u0020\{\n(?:|\u0020{4})\/\*\n(?:\u0020|\u0020{5})\*((?:\u0020<[^>]*?>|\u0020\.\.\.)*?)\n(?:\u0020|\u0020{5})\*\u0020(will\u0020.*?\S)\n(?:\u0020|\u0020{5})\*\/\n(?:\u0020{4}|\u0020{8})\S/
);
textDict = {};
strDict = {};
Object.keys(local.cliDict).sort().forEach(function (key, ii) {
if (key[0] === "_" && key !== "_default") {
return;
}
text = String(local.cliDict[key]);
str = String(local.cliDict[key]);
if (key === "_default") {
key = "";
}
textDict[text] = textDict[text] || (ii + 2);
ii = textDict[text];
strDict[str] = strDict[str] || (ii + 2);
ii = strDict[str];
if (commandList[ii]) {
commandList[ii].command.push(key);
return;
}
try {
commandList[ii] = opt.rgxComment.exec(text);
commandList[ii] = opt.rgxComment.exec(str);
commandList[ii] = {
argList: local.coalesce(commandList[ii][1], "").trim(),
command: [
Expand All @@ -844,7 +696,7 @@ local.cliRun = function (opt) {
+ key
+ ":\nnew RegExp("
+ JSON.stringify(opt.rgxComment.source)
+ ").exec(" + JSON.stringify(text).replace((
+ ").exec(" + JSON.stringify(str).replace((
/\\\\/g
), "\u0000").replace((
/\\n/g
Expand All @@ -854,9 +706,9 @@ local.cliRun = function (opt) {
));
}
});
text = "";
text += packageJson.name + " (" + packageJson.version + ")\n\n";
text += commandList.filter(function (elem) {
str = "";
str += packageJson.name + " (" + packageJson.version + ")\n\n";
str += commandList.filter(function (elem) {
return elem;
}).map(function (elem, ii) {
elem.command = elem.command.filter(function (elem) {
Expand All @@ -883,7 +735,7 @@ local.cliRun = function (opt) {
+ elem.argList.join(" ")
);
}).join("\n\n");
console.log(text);
console.log(str);
};
local.cliDict["--eval"] = local.cliDict["--eval"] || local.cliDict._eval;
local.cliDict["--help"] = local.cliDict["--help"] || local.cliDict._help;
Expand Down Expand Up @@ -989,7 +841,7 @@ local.onErrorWithStack = function (onError) {
if (
err
&& typeof err.stack === "string"
&& err !== local.errDefault
&& err !== local.errorDefault
&& String(err.stack).indexOf(stack.split("\n")[2]) < 0
) {
err.stack += "\n" + stack;
Expand Down
Loading

0 comments on commit 7a9661c

Please sign in to comment.