@difizen/libro-common 0.0.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/es/array.d.ts +368 -0
- package/es/array.d.ts.map +1 -0
- package/es/array.js +577 -0
- package/es/display-wrapper.d.ts +6 -0
- package/es/display-wrapper.d.ts.map +1 -0
- package/es/display-wrapper.js +12 -0
- package/es/index.d.ts +11 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +10 -0
- package/es/iter.d.ts +147 -0
- package/es/iter.d.ts.map +1 -0
- package/es/iter.js +162 -0
- package/es/json.d.ts +126 -0
- package/es/json.d.ts.map +1 -0
- package/es/json.js +274 -0
- package/es/path.d.ts +97 -0
- package/es/path.d.ts.map +1 -0
- package/es/path.js +60 -0
- package/es/polling/index.d.ts +3 -0
- package/es/polling/index.d.ts.map +1 -0
- package/es/polling/index.js +2 -0
- package/es/polling/poll.d.ts +193 -0
- package/es/polling/poll.d.ts.map +1 -0
- package/es/polling/poll.js +501 -0
- package/es/polling/protocol.d.ts +120 -0
- package/es/polling/protocol.d.ts.map +1 -0
- package/es/polling/protocol.js +13 -0
- package/es/posix.d.ts +2 -0
- package/es/posix.d.ts.map +1 -0
- package/es/posix.js +71 -0
- package/es/protocol/cell-protocol.d.ts +181 -0
- package/es/protocol/cell-protocol.d.ts.map +1 -0
- package/es/protocol/cell-protocol.js +1 -0
- package/es/protocol/index.d.ts +4 -0
- package/es/protocol/index.d.ts.map +1 -0
- package/es/protocol/index.js +3 -0
- package/es/protocol/notebook-protocol.d.ts +63 -0
- package/es/protocol/notebook-protocol.d.ts.map +1 -0
- package/es/protocol/notebook-protocol.js +41 -0
- package/es/protocol/output-protocol.d.ts +125 -0
- package/es/protocol/output-protocol.d.ts.map +1 -0
- package/es/protocol/output-protocol.js +1 -0
- package/es/sanitizer.d.ts +44 -0
- package/es/sanitizer.d.ts.map +1 -0
- package/es/sanitizer.js +659 -0
- package/es/url.d.ts +98 -0
- package/es/url.d.ts.map +1 -0
- package/es/url.js +134 -0
- package/es/utils.d.ts +57 -0
- package/es/utils.d.ts.map +1 -0
- package/es/utils.js +124 -0
- package/package.json +62 -0
- package/src/array.ts +608 -0
- package/src/display-wrapper.tsx +11 -0
- package/src/index.ts +10 -0
- package/src/iter.ts +199 -0
- package/src/json.ts +321 -0
- package/src/path.ts +138 -0
- package/src/polling/index.ts +2 -0
- package/src/polling/poll.ts +508 -0
- package/src/polling/protocol.ts +145 -0
- package/src/posix.ts +75 -0
- package/src/protocol/cell-protocol.ts +215 -0
- package/src/protocol/index.ts +3 -0
- package/src/protocol/notebook-protocol.ts +73 -0
- package/src/protocol/output-protocol.ts +162 -0
- package/src/sanitizer.ts +944 -0
- package/src/url.ts +157 -0
- package/src/utils.ts +145 -0
package/es/url.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The namespace for URL-related functions.
|
|
3
|
+
*/
|
|
4
|
+
export declare class URL {
|
|
5
|
+
/**
|
|
6
|
+
* Parse URL and retrieve hostname
|
|
7
|
+
*
|
|
8
|
+
* @param url - The URL string to parse
|
|
9
|
+
*
|
|
10
|
+
* @returns a hostname string value
|
|
11
|
+
*/
|
|
12
|
+
static getHostName(url: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Normalize a url.
|
|
15
|
+
*/
|
|
16
|
+
static normalize(url: string): string;
|
|
17
|
+
static normalize(url: undefined): undefined;
|
|
18
|
+
static normalize(url: string | undefined): string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Join a sequence of url components and normalizes as in node `path.join`.
|
|
21
|
+
*
|
|
22
|
+
* @param parts - The url components.
|
|
23
|
+
*
|
|
24
|
+
* @returns the joined url.
|
|
25
|
+
*/
|
|
26
|
+
static join(...parts: string[]): string;
|
|
27
|
+
/**
|
|
28
|
+
* Encode the components of a multi-segment url.
|
|
29
|
+
*
|
|
30
|
+
* @param url - The url to encode.
|
|
31
|
+
*
|
|
32
|
+
* @returns the encoded url.
|
|
33
|
+
*
|
|
34
|
+
* #### Notes
|
|
35
|
+
* Preserves the `'/'` separators.
|
|
36
|
+
* Should not include the base url, since all parts are escaped.
|
|
37
|
+
*/
|
|
38
|
+
static encodeParts(url: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Parse a url into a URL object.
|
|
41
|
+
*
|
|
42
|
+
* @param urlString - The URL string to parse.
|
|
43
|
+
*
|
|
44
|
+
* @returns A URL object.
|
|
45
|
+
*/
|
|
46
|
+
static parse(url: string): IUrl;
|
|
47
|
+
/**
|
|
48
|
+
* Test whether the url is a local url.
|
|
49
|
+
*
|
|
50
|
+
* #### Notes
|
|
51
|
+
* This function returns `false` for any fully qualified url, including
|
|
52
|
+
* `data:`, `file:`, and `//` protocol URLs.
|
|
53
|
+
*/
|
|
54
|
+
static isLocal(url: string): boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The interface for a URL object
|
|
58
|
+
*/
|
|
59
|
+
export interface IUrl {
|
|
60
|
+
/**
|
|
61
|
+
* The full URL string that was parsed with both the protocol and host
|
|
62
|
+
* components converted to lower-case.
|
|
63
|
+
*/
|
|
64
|
+
href: string;
|
|
65
|
+
/**
|
|
66
|
+
* Identifies the URL's lower-cased protocol scheme.
|
|
67
|
+
*/
|
|
68
|
+
protocol: string;
|
|
69
|
+
/**
|
|
70
|
+
* The full lower-cased host portion of the URL, including the port if
|
|
71
|
+
* specified.
|
|
72
|
+
*/
|
|
73
|
+
host: string;
|
|
74
|
+
/**
|
|
75
|
+
* The lower-cased host name portion of the host component without the
|
|
76
|
+
* port included.
|
|
77
|
+
*/
|
|
78
|
+
hostname: string;
|
|
79
|
+
/**
|
|
80
|
+
* The numeric port portion of the host component.
|
|
81
|
+
*/
|
|
82
|
+
port: string;
|
|
83
|
+
/**
|
|
84
|
+
* The entire path section of the URL.
|
|
85
|
+
*/
|
|
86
|
+
pathname: string;
|
|
87
|
+
/**
|
|
88
|
+
* The "fragment" portion of the URL including the leading ASCII hash
|
|
89
|
+
* `(#)` character
|
|
90
|
+
*/
|
|
91
|
+
hash: string;
|
|
92
|
+
/**
|
|
93
|
+
* The search element, including leading question mark (`'?'`), if any,
|
|
94
|
+
* of the URL.
|
|
95
|
+
*/
|
|
96
|
+
search?: string;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=url.d.ts.map
|
package/es/url.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,qBAAa,GAAG;IACd;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAGvC;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IACrC,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,SAAS;IAC3C,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS;IAa7D;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM;IAmBvC;;;;;;;;;;OAUG;IACH,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAGvC;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAQ/B;;;;;;OAMG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;CAOrC;AAED;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
package/es/url.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
8
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
10
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
12
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
13
|
+
import { isWeb } from '@difizen/mana-common';
|
|
14
|
+
import { posix } from 'path-browserify';
|
|
15
|
+
import urlparse from 'url-parse';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The namespace for URL-related functions.
|
|
19
|
+
*/
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
21
|
+
export var URL = /*#__PURE__*/function () {
|
|
22
|
+
function URL() {
|
|
23
|
+
_classCallCheck(this, URL);
|
|
24
|
+
}
|
|
25
|
+
_createClass(URL, null, [{
|
|
26
|
+
key: "getHostName",
|
|
27
|
+
value:
|
|
28
|
+
/**
|
|
29
|
+
* Parse URL and retrieve hostname
|
|
30
|
+
*
|
|
31
|
+
* @param url - The URL string to parse
|
|
32
|
+
*
|
|
33
|
+
* @returns a hostname string value
|
|
34
|
+
*/
|
|
35
|
+
function getHostName(url) {
|
|
36
|
+
return urlparse(url).hostname;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Normalize a url.
|
|
40
|
+
*/
|
|
41
|
+
}, {
|
|
42
|
+
key: "normalize",
|
|
43
|
+
value: function normalize(url) {
|
|
44
|
+
if (!url) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
if (isWeb) {
|
|
48
|
+
var a = document.createElement('a');
|
|
49
|
+
a.href = url;
|
|
50
|
+
return a.toString();
|
|
51
|
+
}
|
|
52
|
+
return urlparse(url).toString();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Join a sequence of url components and normalizes as in node `path.join`.
|
|
57
|
+
*
|
|
58
|
+
* @param parts - The url components.
|
|
59
|
+
*
|
|
60
|
+
* @returns the joined url.
|
|
61
|
+
*/
|
|
62
|
+
}, {
|
|
63
|
+
key: "join",
|
|
64
|
+
value: function join() {
|
|
65
|
+
for (var _len = arguments.length, parts = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
66
|
+
parts[_key] = arguments[_key];
|
|
67
|
+
}
|
|
68
|
+
var u = urlparse(parts[0], {});
|
|
69
|
+
// Schema-less URL can be only parsed as relative to a base URL
|
|
70
|
+
// see https://github.com/unshiftio/url-parse/issues/219#issuecomment-1002219326
|
|
71
|
+
var isSchemaLess = u.protocol === '' && u.slashes;
|
|
72
|
+
if (isSchemaLess) {
|
|
73
|
+
u = urlparse(parts[0], 'https:' + parts[0]);
|
|
74
|
+
}
|
|
75
|
+
var prefix = "".concat(isSchemaLess ? '' : u.protocol).concat(u.slashes ? '//' : '').concat(u.auth).concat(u.auth ? '@' : '').concat(u.host);
|
|
76
|
+
// If there was a prefix, then the first path must start at the root.
|
|
77
|
+
var path = posix.join.apply(posix, ["".concat(!!prefix && u.pathname[0] !== '/' ? '/' : '').concat(u.pathname)].concat(_toConsumableArray(parts.slice(1))));
|
|
78
|
+
return "".concat(prefix).concat(path === '.' ? '' : path);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Encode the components of a multi-segment url.
|
|
83
|
+
*
|
|
84
|
+
* @param url - The url to encode.
|
|
85
|
+
*
|
|
86
|
+
* @returns the encoded url.
|
|
87
|
+
*
|
|
88
|
+
* #### Notes
|
|
89
|
+
* Preserves the `'/'` separators.
|
|
90
|
+
* Should not include the base url, since all parts are escaped.
|
|
91
|
+
*/
|
|
92
|
+
}, {
|
|
93
|
+
key: "encodeParts",
|
|
94
|
+
value: function encodeParts(url) {
|
|
95
|
+
return URL.join.apply(URL, _toConsumableArray(url.split('/').map(encodeURIComponent)));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Parse a url into a URL object.
|
|
99
|
+
*
|
|
100
|
+
* @param urlString - The URL string to parse.
|
|
101
|
+
*
|
|
102
|
+
* @returns A URL object.
|
|
103
|
+
*/
|
|
104
|
+
}, {
|
|
105
|
+
key: "parse",
|
|
106
|
+
value: function parse(url) {
|
|
107
|
+
if (typeof document !== 'undefined' && document) {
|
|
108
|
+
var a = document.createElement('a');
|
|
109
|
+
a.href = url;
|
|
110
|
+
return a;
|
|
111
|
+
}
|
|
112
|
+
return urlparse(url);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Test whether the url is a local url.
|
|
116
|
+
*
|
|
117
|
+
* #### Notes
|
|
118
|
+
* This function returns `false` for any fully qualified url, including
|
|
119
|
+
* `data:`, `file:`, and `//` protocol URLs.
|
|
120
|
+
*/
|
|
121
|
+
}, {
|
|
122
|
+
key: "isLocal",
|
|
123
|
+
value: function isLocal(url) {
|
|
124
|
+
var _URL$parse = URL.parse(url),
|
|
125
|
+
protocol = _URL$parse.protocol;
|
|
126
|
+
return (!protocol || url.toLowerCase().indexOf(protocol) !== 0) && url.indexOf('/') !== 0;
|
|
127
|
+
}
|
|
128
|
+
}]);
|
|
129
|
+
return URL;
|
|
130
|
+
}();
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The interface for a URL object
|
|
134
|
+
*/
|
package/es/utils.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { PartialJSONObject, PartialJSONValue } from './json.js';
|
|
2
|
+
import type { ICell, ICodeCell, IMarkdownCell, IRawCell } from './protocol/cell-protocol.js';
|
|
3
|
+
import type { MultilineString } from './protocol/notebook-protocol.js';
|
|
4
|
+
import type { IDisplayData, IDisplayUpdate, IError, IExecuteResult, IOutput, IStream } from './protocol/output-protocol.js';
|
|
5
|
+
/**
|
|
6
|
+
* Validate a mime type/value pair.
|
|
7
|
+
*
|
|
8
|
+
* @param type - The mimetype name.
|
|
9
|
+
*
|
|
10
|
+
* @param value - The value associated with the type.
|
|
11
|
+
*
|
|
12
|
+
* @returns Whether the type/value pair are valid.
|
|
13
|
+
*/
|
|
14
|
+
export declare function validateMimeValue(type: string, value: MultilineString | PartialJSONObject): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* join multiline string, normalizing line endings to \n
|
|
17
|
+
* @param value
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare function concatMultilineString(value: MultilineString): string;
|
|
21
|
+
/**
|
|
22
|
+
* Test whether a cell is a raw cell.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isRaw(cell: ICell): cell is IRawCell;
|
|
25
|
+
/**
|
|
26
|
+
* Test whether a cell is a markdown cell.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isMarkdown(cell: ICell): cell is IMarkdownCell;
|
|
29
|
+
/**
|
|
30
|
+
* Test whether a cell is a code cell.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isCode(cell: ICell): cell is ICodeCell;
|
|
33
|
+
/**
|
|
34
|
+
* Test whether a cell is a code cell.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isOutput(output: PartialJSONValue | IOutput[] | undefined): output is IOutput[];
|
|
37
|
+
/**
|
|
38
|
+
* Test whether an output is an execute result.
|
|
39
|
+
*/
|
|
40
|
+
export declare function isExecuteResult(output: IOutput): output is IExecuteResult;
|
|
41
|
+
/**
|
|
42
|
+
* Test whether an output is from display data.
|
|
43
|
+
*/
|
|
44
|
+
export declare function isDisplayData(output: IOutput): output is IDisplayData;
|
|
45
|
+
/**
|
|
46
|
+
* Test whether an output is from updated display data.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isDisplayUpdate(output: IOutput): output is IDisplayUpdate;
|
|
49
|
+
/**
|
|
50
|
+
* Test whether an output is from a stream.
|
|
51
|
+
*/
|
|
52
|
+
export declare function isStream(output: IOutput): output is IStream;
|
|
53
|
+
/**
|
|
54
|
+
* Test whether an output is an error.
|
|
55
|
+
*/
|
|
56
|
+
export declare function isError(output: IOutput): output is IError;
|
|
57
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAErE,OAAO,KAAK,EACV,KAAK,EACL,SAAS,EACT,aAAa,EACb,QAAQ,EACT,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,MAAM,EACN,cAAc,EACd,OAAO,EACP,OAAO,EACR,MAAM,+BAA+B,CAAC;AAEvC;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,eAAe,GAAG,iBAAiB,GACzC,OAAO,CAoCT;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAMpE;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,IAAI,QAAQ,CAEnD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,IAAI,aAAa,CAE7D;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,IAAI,SAAS,CAErD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACtB,MAAM,EAAE,gBAAgB,GAAG,OAAO,EAAE,GAAG,SAAS,GAC/C,MAAM,IAAI,OAAO,EAAE,CAErB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,cAAc,CAEzE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,YAAY,CAErE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,cAAc,CAEzE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,OAAO,CAE3D;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,MAAM,CAEzD"}
|
package/es/utils.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { isObject } from "./json.js";
|
|
2
|
+
/**
|
|
3
|
+
* Validate a mime type/value pair.
|
|
4
|
+
*
|
|
5
|
+
* @param type - The mimetype name.
|
|
6
|
+
*
|
|
7
|
+
* @param value - The value associated with the type.
|
|
8
|
+
*
|
|
9
|
+
* @returns Whether the type/value pair are valid.
|
|
10
|
+
*/
|
|
11
|
+
export function validateMimeValue(type, value) {
|
|
12
|
+
// Check if "application/json" or "application/foo+json"
|
|
13
|
+
var jsonTest = /^application\/.+\+json$/;
|
|
14
|
+
var isJSONType = type === 'application/json' || jsonTest.test(type);
|
|
15
|
+
var isString = function isString(x) {
|
|
16
|
+
return Object.prototype.toString.call(x) === '[object String]';
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// If it is an array, make sure if is not a JSON type and it is an
|
|
20
|
+
// array of strings.
|
|
21
|
+
if (Array.isArray(value)) {
|
|
22
|
+
if (isJSONType) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
var valid = true;
|
|
26
|
+
value.forEach(function (v) {
|
|
27
|
+
if (!isString(v)) {
|
|
28
|
+
valid = false;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return valid;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// If it is a string, make sure we are not a JSON type.
|
|
35
|
+
if (isString(value)) {
|
|
36
|
+
return !isJSONType;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// It is not a string, make sure it is a JSON type.
|
|
40
|
+
if (!isJSONType) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// It is a JSON type, make sure it is a valid JSON object.
|
|
45
|
+
return isObject(value);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* join multiline string, normalizing line endings to \n
|
|
50
|
+
* @param value
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
export function concatMultilineString(value) {
|
|
54
|
+
if (Array.isArray(value)) {
|
|
55
|
+
return value.map(function (s) {
|
|
56
|
+
return s.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
57
|
+
}).join('');
|
|
58
|
+
} else {
|
|
59
|
+
return value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Test whether a cell is a raw cell.
|
|
65
|
+
*/
|
|
66
|
+
export function isRaw(cell) {
|
|
67
|
+
return cell.cell_type === 'raw';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Test whether a cell is a markdown cell.
|
|
72
|
+
*/
|
|
73
|
+
export function isMarkdown(cell) {
|
|
74
|
+
return cell.cell_type === 'markdown';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Test whether a cell is a code cell.
|
|
79
|
+
*/
|
|
80
|
+
export function isCode(cell) {
|
|
81
|
+
return cell.cell_type === 'code';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Test whether a cell is a code cell.
|
|
86
|
+
*/
|
|
87
|
+
export function isOutput(output) {
|
|
88
|
+
return !!(output && output instanceof Array);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Test whether an output is an execute result.
|
|
93
|
+
*/
|
|
94
|
+
export function isExecuteResult(output) {
|
|
95
|
+
return output.output_type === 'execute_result';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Test whether an output is from display data.
|
|
100
|
+
*/
|
|
101
|
+
export function isDisplayData(output) {
|
|
102
|
+
return output.output_type === 'display_data';
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Test whether an output is from updated display data.
|
|
107
|
+
*/
|
|
108
|
+
export function isDisplayUpdate(output) {
|
|
109
|
+
return output.output_type === 'update_display_data';
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Test whether an output is from a stream.
|
|
114
|
+
*/
|
|
115
|
+
export function isStream(output) {
|
|
116
|
+
return output.output_type === 'stream';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Test whether an output is an error.
|
|
121
|
+
*/
|
|
122
|
+
export function isError(output) {
|
|
123
|
+
return output.output_type === 'error';
|
|
124
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@difizen/libro-common",
|
|
3
|
+
"version": "0.0.2-alpha.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"libro",
|
|
7
|
+
"notebook"
|
|
8
|
+
],
|
|
9
|
+
"repository": "git@github.com:difizen/libro.git",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"typings": "./es/index.d.ts",
|
|
15
|
+
"default": "./es/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./mock": {
|
|
18
|
+
"typings": "./es/mock/index.d.ts",
|
|
19
|
+
"default": "./es/mock/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./es/mock": {
|
|
22
|
+
"typings": "./es/mock/index.d.ts",
|
|
23
|
+
"default": "./es/mock/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"main": "es/index.js",
|
|
28
|
+
"module": "es/index.js",
|
|
29
|
+
"typings": "es/index.d.ts",
|
|
30
|
+
"files": [
|
|
31
|
+
"es",
|
|
32
|
+
"src"
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@difizen/mana-common": "alpha",
|
|
36
|
+
"path-browserify": "^1.0.0",
|
|
37
|
+
"sanitize-html": "^2.7.2",
|
|
38
|
+
"url-parse": "^1.5.10"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/react": "^18.2.25",
|
|
42
|
+
"@types/path-browserify": "^1.0.0",
|
|
43
|
+
"@types/sanitize-html": "^2.6.2",
|
|
44
|
+
"@types/url-parse": "^1.4.8"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"react": "^18.2.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"setup": "father build",
|
|
51
|
+
"build": "father build",
|
|
52
|
+
"test": ": Note: lint task is delegated to test:* scripts",
|
|
53
|
+
"test:vitest": "vitest run",
|
|
54
|
+
"test:jest": "jest",
|
|
55
|
+
"coverage": ": Note: lint task is delegated to coverage:* scripts",
|
|
56
|
+
"coverage:vitest": "vitest run --coverage",
|
|
57
|
+
"coverage:jest": "jest --coverage",
|
|
58
|
+
"lint": ": Note: lint task is delegated to lint:* scripts",
|
|
59
|
+
"lint:eslint": "eslint src",
|
|
60
|
+
"lint:tsc": "tsc --noEmit"
|
|
61
|
+
}
|
|
62
|
+
}
|