@kwiz/common 1.0.2 → 1.0.3
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/package.json +1 -1
- package/src/_dependencies.ts +0 -2
- package/src/helpers/Guid.ts +0 -182
- package/src/helpers/_dependencies.ts +0 -3
- package/src/helpers/base64.ts +0 -174
- package/src/helpers/browser.test.js +0 -9
- package/src/helpers/browser.ts +0 -1299
- package/src/helpers/browserinfo.ts +0 -293
- package/src/helpers/collections.base.test.js +0 -26
- package/src/helpers/collections.base.ts +0 -439
- package/src/helpers/collections.ts +0 -108
- package/src/helpers/color.ts +0 -55
- package/src/helpers/cookies.ts +0 -55
- package/src/helpers/date.test.js +0 -97
- package/src/helpers/date.ts +0 -163
- package/src/helpers/debug.ts +0 -187
- package/src/helpers/emails.ts +0 -7
- package/src/helpers/eval.ts +0 -5
- package/src/helpers/file.test.js +0 -51
- package/src/helpers/file.ts +0 -59
- package/src/helpers/flatted.ts +0 -150
- package/src/helpers/functions.ts +0 -17
- package/src/helpers/graph/calendar.types.ts +0 -11
- package/src/helpers/http.ts +0 -70
- package/src/helpers/images.ts +0 -23
- package/src/helpers/index.ts +0 -29
- package/src/helpers/json.ts +0 -39
- package/src/helpers/md5.ts +0 -190
- package/src/helpers/objects.test.js +0 -27
- package/src/helpers/objects.ts +0 -256
- package/src/helpers/promises.test.js +0 -18
- package/src/helpers/promises.ts +0 -102
- package/src/helpers/random.ts +0 -27
- package/src/helpers/scheduler/scheduler.test.js +0 -104
- package/src/helpers/scheduler/scheduler.ts +0 -132
- package/src/helpers/sharepoint.ts +0 -681
- package/src/helpers/strings.test.js +0 -43
- package/src/helpers/strings.ts +0 -288
- package/src/helpers/typecheckers.test.js +0 -35
- package/src/helpers/typecheckers.ts +0 -263
- package/src/helpers/url.test.js +0 -18
- package/src/helpers/url.ts +0 -202
- package/src/helpers/urlhelper.ts +0 -104
- package/src/index.ts +0 -24
- package/src/types/common.types.ts +0 -16
- package/src/types/flatted.types.ts +0 -60
- package/src/types/globals.types.ts +0 -7
- package/src/types/graph/calendar.types.ts +0 -81
- package/src/types/graph/index.ts +0 -1
- package/src/types/index.ts +0 -12
- package/src/types/knownscript.types.ts +0 -19
- package/src/types/libs/datajs.types.ts +0 -29
- package/src/types/libs/ics.types.ts +0 -31
- package/src/types/libs/index.ts +0 -4
- package/src/types/libs/msal.types.ts +0 -79
- package/src/types/locales.ts +0 -125
- package/src/types/localstoragecache.types.ts +0 -9
- package/src/types/moment.ts +0 -7
- package/src/types/regex.types.ts +0 -17
- package/src/types/rest.types.ts +0 -94
- package/src/types/sharepoint.types.ts +0 -1413
- package/src/types/sharepoint.utils.types.ts +0 -246
- package/src/utils/_dependencies.ts +0 -4
- package/src/utils/base64.ts +0 -27
- package/src/utils/consolelogger.ts +0 -315
- package/src/utils/date.ts +0 -36
- package/src/utils/emails.ts +0 -25
- package/src/utils/index.ts +0 -13
- package/src/utils/knownscript.ts +0 -280
- package/src/utils/localstoragecache.ts +0 -419
- package/src/utils/rest.ts +0 -465
- package/src/utils/script.ts +0 -168
- package/src/utils/sharepoint.rest/common.ts +0 -149
- package/src/utils/sharepoint.rest/date.ts +0 -61
- package/src/utils/sharepoint.rest/file.folder.ts +0 -368
- package/src/utils/sharepoint.rest/index.ts +0 -11
- package/src/utils/sharepoint.rest/item.ts +0 -456
- package/src/utils/sharepoint.rest/list.ts +0 -1144
- package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +0 -750
- package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +0 -265
- package/src/utils/sharepoint.rest/listutils/common.ts +0 -202
- package/src/utils/sharepoint.rest/user-search.ts +0 -254
- package/src/utils/sharepoint.rest/user.ts +0 -447
- package/src/utils/sharepoint.rest/web.ts +0 -1031
- package/src/utils/sod.ts +0 -193
- package/tsconfig.json +0 -21
package/src/helpers/flatted.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
/*! (c) 2020 Andrea Giammarchi */
|
|
4
|
-
|
|
5
|
-
import { IFlatted } from "./_dependencies";
|
|
6
|
-
import { isNullOrEmptyArray } from "./typecheckers";
|
|
7
|
-
|
|
8
|
-
/** Version 3.2.9 */
|
|
9
|
-
/**
|
|
10
|
-
* Fast and minimal circular JSON parser.
|
|
11
|
-
* logic example
|
|
12
|
-
```js
|
|
13
|
-
var a = [{one: 1}, {two: '2'}];
|
|
14
|
-
a[0].a = a;
|
|
15
|
-
// a is the main object, will be at index '0'
|
|
16
|
-
// {one: 1} is the second object, index '1'
|
|
17
|
-
// {two: '2'} the third, in '2', and it has a string
|
|
18
|
-
// which will be found at index '3'
|
|
19
|
-
Flatted.stringify(a);
|
|
20
|
-
// [["1","2"],{"one":1,"a":"0"},{"two":"3"},"2"]
|
|
21
|
-
// a[one,two] {one: 1, a} {two: '2'} '2'
|
|
22
|
-
```
|
|
23
|
-
*/
|
|
24
|
-
const { parse: $parse, stringify: $stringify } = JSON;
|
|
25
|
-
const { keys } = Object;
|
|
26
|
-
|
|
27
|
-
const Primitive = String; // it could be Number
|
|
28
|
-
const primitive = 'string'; // it could be 'number'
|
|
29
|
-
|
|
30
|
-
const ignore = {};
|
|
31
|
-
const object = 'object';
|
|
32
|
-
|
|
33
|
-
const noop = (_, value) => value;
|
|
34
|
-
|
|
35
|
-
const primitives = value => (
|
|
36
|
-
value instanceof Primitive ? Primitive(value) : value
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
const Primitives = (_, value) => (
|
|
40
|
-
typeof value === primitive ? new Primitive(value) : value
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const revive = (input, parsed, output, $) => {
|
|
44
|
-
const lazy = [];
|
|
45
|
-
for (let ke = keys(output), { length } = ke, y = 0; y < length; y++) {
|
|
46
|
-
const k = ke[y];
|
|
47
|
-
const value = output[k];
|
|
48
|
-
if (value instanceof Primitive) {
|
|
49
|
-
const tmp = input[value as string];
|
|
50
|
-
if (typeof tmp === object && !parsed.has(tmp)) {
|
|
51
|
-
parsed.add(tmp);
|
|
52
|
-
output[k] = ignore;
|
|
53
|
-
lazy.push({ k, a: [input, parsed, tmp, $] });
|
|
54
|
-
}
|
|
55
|
-
else
|
|
56
|
-
output[k] = $.call(output, k, tmp);
|
|
57
|
-
}
|
|
58
|
-
else if (output[k] !== ignore)
|
|
59
|
-
output[k] = $.call(output, k, value);
|
|
60
|
-
}
|
|
61
|
-
for (let { length } = lazy, i = 0; i < length; i++) {
|
|
62
|
-
const { k, a } = lazy[i];
|
|
63
|
-
output[k] = $.call(output, k, revive.apply(null, a));
|
|
64
|
-
}
|
|
65
|
-
return output;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const set = (known, input, value) => {
|
|
69
|
-
const index = Primitive(input.push(value) - 1);
|
|
70
|
-
known.set(value, index);
|
|
71
|
-
return index;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const parse = (text, reviver?) => {
|
|
75
|
-
const input = $parse(text, Primitives).map(primitives);
|
|
76
|
-
const value = input[0];
|
|
77
|
-
const $ = reviver || noop;
|
|
78
|
-
const tmp = typeof value === object && value ?
|
|
79
|
-
revive(input, new Set, value, $) :
|
|
80
|
-
value;
|
|
81
|
-
return $.call({ '': tmp }, '', tmp);
|
|
82
|
-
};
|
|
83
|
-
//exports.parse = parse;
|
|
84
|
-
|
|
85
|
-
const stringify = (value, replacer?, space?) => {
|
|
86
|
-
const $ = replacer && typeof replacer === object ?
|
|
87
|
-
(k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
|
|
88
|
-
(replacer || noop);
|
|
89
|
-
const known = new Map;
|
|
90
|
-
const input = [];
|
|
91
|
-
const output = [];
|
|
92
|
-
let i = +set(known, input, $.call({ '': value }, '', value));
|
|
93
|
-
let firstRun = !i;
|
|
94
|
-
while (i < input.length) {
|
|
95
|
-
firstRun = true;
|
|
96
|
-
output[i] = $stringify(input[i++], replace, space);
|
|
97
|
-
}
|
|
98
|
-
return '[' + output.join(',') + ']';
|
|
99
|
-
function replace(key, value) {
|
|
100
|
-
if (firstRun) {
|
|
101
|
-
firstRun = !firstRun;
|
|
102
|
-
return value;
|
|
103
|
-
}
|
|
104
|
-
const after = $.call(this, key, value);
|
|
105
|
-
switch (typeof after) {
|
|
106
|
-
case object:
|
|
107
|
-
if (after === null) return after;
|
|
108
|
-
return known.get(after) || set(known, input, after);
|
|
109
|
-
case primitive:
|
|
110
|
-
return known.get(after) || set(known, input, after);
|
|
111
|
-
}
|
|
112
|
-
return after;
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
//exports.stringify = stringify;
|
|
116
|
-
|
|
117
|
-
const toJSON = any => $parse(stringify(any));
|
|
118
|
-
//exports.toJSON = toJSON;
|
|
119
|
-
const fromJSON = any => parse($stringify(any));
|
|
120
|
-
//exports.fromJSON = fromJSON;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
/*! (c) 2020 Andrea Giammarchi */
|
|
124
|
-
/**
|
|
125
|
-
* Fast and minimal circular JSON parser.
|
|
126
|
-
* logic example
|
|
127
|
-
```js
|
|
128
|
-
var a = [{one: 1}, {two: '2'}];
|
|
129
|
-
a[0].a = a;
|
|
130
|
-
// a is the main object, will be at index '0'
|
|
131
|
-
// {one: 1} is the second object, index '1'
|
|
132
|
-
// {two: '2'} the third, in '2', and it has a string
|
|
133
|
-
// which will be found at index '3'
|
|
134
|
-
Flatted.stringify(a);
|
|
135
|
-
// [["1","2"],{"one":1,"a":"0"},{"two":"3"},"2"]
|
|
136
|
-
// a[one,two] {one: 1, a} {two: '2'} '2'
|
|
137
|
-
```
|
|
138
|
-
*/
|
|
139
|
-
export var flatted: IFlatted = {
|
|
140
|
-
toJSON: toJSON,
|
|
141
|
-
fromJSON: fromJSON,
|
|
142
|
-
stringify: stringify,
|
|
143
|
-
parse: parse
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
export function flattedClone<T>(obj: T): T {
|
|
147
|
-
if (isNullOrEmptyArray(obj)) return obj;
|
|
148
|
-
//json clone won't work on circular object. must use flatted.
|
|
149
|
-
return flatted.parse(flatted.stringify(obj));
|
|
150
|
-
}
|
package/src/helpers/functions.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { isFunction } from "./typecheckers";
|
|
2
|
-
|
|
3
|
-
export function wrapFunction<ValueType, ReturnType>(f: (value: ValueType) => ReturnType, props: {
|
|
4
|
-
before?: (value: ValueType) => ValueType;
|
|
5
|
-
after?: (value: ValueType, returned: ReturnType) => void;
|
|
6
|
-
}) {
|
|
7
|
-
return (v: ValueType) => {
|
|
8
|
-
if (isFunction(props.before)) {
|
|
9
|
-
v = props.before(v);
|
|
10
|
-
}
|
|
11
|
-
let result = f(v);
|
|
12
|
-
if (isFunction(props.after))
|
|
13
|
-
props.after(v, result);
|
|
14
|
-
|
|
15
|
-
return result;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { IGraphEventAttendee, IGraphEventUser } from "../_dependencies";
|
|
2
|
-
import { isNullOrEmptyString } from "../typecheckers";
|
|
3
|
-
|
|
4
|
-
export function IsGraphEventUser(obj: any): obj is IGraphEventUser {
|
|
5
|
-
let asEA = obj as IGraphEventUser;
|
|
6
|
-
return asEA && asEA.emailAddress && !isNullOrEmptyString(asEA.emailAddress.address);
|
|
7
|
-
}
|
|
8
|
-
export function IsGraphEventAttendee(obj: any): obj is IGraphEventAttendee {
|
|
9
|
-
let asEA = obj as IGraphEventAttendee;
|
|
10
|
-
return IsGraphEventUser(obj) && asEA.status && !isNullOrEmptyString(asEA.type);
|
|
11
|
-
}
|
package/src/helpers/http.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { objectValues } from "./objects";
|
|
2
|
-
import { isNullOrUndefined } from "./typecheckers";
|
|
3
|
-
|
|
4
|
-
// eslint-disable-next-line no-shadow
|
|
5
|
-
export enum CommonHttpHeaderNames {
|
|
6
|
-
Accept = "Accept",
|
|
7
|
-
Authorization = "Authorization",
|
|
8
|
-
ContentType = "content-type",
|
|
9
|
-
XHTTPMethod = "X-HTTP-Method",
|
|
10
|
-
XRapidApiHost = "x-rapidapi-host",
|
|
11
|
-
XRapidApiKey = "x-rapidapi-key"
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// eslint-disable-next-line no-shadow
|
|
15
|
-
enum AcceptOrContentTypeHeaderValues {
|
|
16
|
-
JsonVerbose = "application/json; odata=verbose",
|
|
17
|
-
JsonMinimal = "application/json; odata=minimal",
|
|
18
|
-
JsonNometadata = "application/json; odata=nometadata"
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// eslint-disable-next-line no-shadow
|
|
22
|
-
enum AuthorizationHeaderValues {
|
|
23
|
-
Bearer = "Bearer [token]",
|
|
24
|
-
Basic = "Basic [user]:[password]"
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// eslint-disable-next-line no-shadow
|
|
28
|
-
enum XHttpMethodHeaderValues {
|
|
29
|
-
MERGE = "MERGE",
|
|
30
|
-
DELETE = "DELETE",
|
|
31
|
-
PUT = "PUT"
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function GetCommonHeaderNames() {
|
|
35
|
-
return objectValues<CommonHttpHeaderNames>(CommonHttpHeaderNames);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function GetCommonHeaderValueSuggestions(headerName: CommonHttpHeaderNames | string) {
|
|
39
|
-
if (isNullOrUndefined(headerName)) {
|
|
40
|
-
return [];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
let parsedHeaderName = _getValueByKeyForStringEnum(headerName);
|
|
44
|
-
|
|
45
|
-
if (isNullOrUndefined(parsedHeaderName)) {
|
|
46
|
-
return [];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
switch (parsedHeaderName) {
|
|
50
|
-
case CommonHttpHeaderNames.Accept:
|
|
51
|
-
case CommonHttpHeaderNames.ContentType:
|
|
52
|
-
return objectValues<AcceptOrContentTypeHeaderValues>(AcceptOrContentTypeHeaderValues);
|
|
53
|
-
case CommonHttpHeaderNames.Authorization:
|
|
54
|
-
return objectValues<AuthorizationHeaderValues>(AuthorizationHeaderValues);
|
|
55
|
-
case CommonHttpHeaderNames.XHTTPMethod:
|
|
56
|
-
return objectValues<XHttpMethodHeaderValues>(XHttpMethodHeaderValues);
|
|
57
|
-
default:
|
|
58
|
-
return [];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function _getValueByKeyForStringEnum(keyOrValue: string | CommonHttpHeaderNames) {
|
|
63
|
-
let found = objectValues<CommonHttpHeaderNames>(CommonHttpHeaderNames).filter((value) => {
|
|
64
|
-
return value === keyOrValue;
|
|
65
|
-
})[0];
|
|
66
|
-
if (isNullOrUndefined(found)) {
|
|
67
|
-
found = CommonHttpHeaderNames[keyOrValue as keyof typeof CommonHttpHeaderNames];
|
|
68
|
-
}
|
|
69
|
-
return found;
|
|
70
|
-
}
|
package/src/helpers/images.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const prefix = "https://apps.kwizcom.com/products/common/images/";
|
|
2
|
-
|
|
3
|
-
export const LOGO_ANIM_SMALL = `${prefix}logo/anim-small.gif`;
|
|
4
|
-
export const LOGO_ANIM = `${prefix}logo/anim.gif`;
|
|
5
|
-
|
|
6
|
-
export const LOGO_BLACK_HORIZONTAL = `${prefix}logo/black/horizontal.png`;
|
|
7
|
-
export const LOGO_BLACK_SQUARE = `${prefix}logo/black/square.png`;
|
|
8
|
-
export const LOGO_BLACK_VERTICAL = `${prefix}logo/black/vertical.png`;
|
|
9
|
-
|
|
10
|
-
export const LOGO_BLUE_HORIZONTAL = `${prefix}logo/blue/horizontal.png`;
|
|
11
|
-
export const LOGO_BLUE_SQUARE = `${prefix}logo/blue/square.png`;
|
|
12
|
-
export const LOGO_BLUE_VERTICAL = `${prefix}logo/blue/vertical.png`;
|
|
13
|
-
|
|
14
|
-
export const LOGO_CYAN_HORIZONTAL = `${prefix}logo/cyan/horizontal.png`;
|
|
15
|
-
export const LOGO_CYAN_VERTICAL = `${prefix}logo/cyan/vertical.png`;
|
|
16
|
-
|
|
17
|
-
export const LOGO_GRAD_HORIZONTAL = `${prefix}logo/grad/horizontal.png`;
|
|
18
|
-
export const LOGO_GRAD_SQUARE = `${prefix}logo/grad/square.png`;
|
|
19
|
-
export const LOGO_GRAD_VERTICAL = `${prefix}logo/grad/vertical.png`;
|
|
20
|
-
|
|
21
|
-
export const LOGO_WHITE_HORIZONTAL = `${prefix}logo/white/horizontal.png`;
|
|
22
|
-
export const LOGO_WHITE_SQUARE = `${prefix}logo/white/square.png`;
|
|
23
|
-
export const LOGO_WHITE_VERTICAL = `${prefix}logo/white/vertical.png`;
|
package/src/helpers/index.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export * from './Guid';
|
|
2
|
-
export * from './base64';
|
|
3
|
-
export * from './browser';
|
|
4
|
-
export * from './browserinfo';
|
|
5
|
-
export * from './collections';
|
|
6
|
-
export * from './collections.base';
|
|
7
|
-
export * from './color';
|
|
8
|
-
export * from './cookies';
|
|
9
|
-
export * from './date';
|
|
10
|
-
export * from './debug';
|
|
11
|
-
export * from './emails';
|
|
12
|
-
export * from './eval';
|
|
13
|
-
export * from './file';
|
|
14
|
-
export * from './flatted';
|
|
15
|
-
export * from './functions';
|
|
16
|
-
export * from './graph/calendar.types';
|
|
17
|
-
export * from './http';
|
|
18
|
-
export * from './images';
|
|
19
|
-
export * from './json';
|
|
20
|
-
export * from './md5';
|
|
21
|
-
export * from './objects';
|
|
22
|
-
export * from './promises';
|
|
23
|
-
export * from './random';
|
|
24
|
-
export * from './scheduler/scheduler';
|
|
25
|
-
export * from './sharepoint';
|
|
26
|
-
export * from './strings';
|
|
27
|
-
export * from './typecheckers';
|
|
28
|
-
export * from './url';
|
|
29
|
-
export * from './urlhelper';
|
package/src/helpers/json.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { eval2 } from "./eval";
|
|
2
|
-
import { isFunction, isNullOrEmptyString } from "./typecheckers";
|
|
3
|
-
|
|
4
|
-
export function jsonParse<T = any>(str: string) {
|
|
5
|
-
if (isNullOrEmptyString(str)) {
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
if (JSON) {
|
|
10
|
-
if (isFunction(JSON.parse)) {
|
|
11
|
-
try {
|
|
12
|
-
var v = JSON.parse(str);
|
|
13
|
-
return v as T;
|
|
14
|
-
} catch (ex) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
try {
|
|
20
|
-
var v2 = eval2("(" + str + ")");
|
|
21
|
-
|
|
22
|
-
return v2 as T;
|
|
23
|
-
} catch (ex1) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** stringify JSON object, but also sorts properties alphabetically */
|
|
29
|
-
export function jsonStringify(obj: any, space?: number): string {
|
|
30
|
-
if (isNullOrEmptyString(obj)) return "";
|
|
31
|
-
var allKeys = [];
|
|
32
|
-
JSON.stringify(obj, (key, value) => {
|
|
33
|
-
if (!allKeys.includes(key))
|
|
34
|
-
allKeys.push(key);
|
|
35
|
-
return value;
|
|
36
|
-
});
|
|
37
|
-
allKeys.sort();
|
|
38
|
-
return JSON.stringify(obj, allKeys, space);
|
|
39
|
-
}
|
package/src/helpers/md5.ts
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
/** fastest implementation
|
|
2
|
-
* from: http://www.myersdaily.org/joseph/javascript/md5-text.html
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/** Get an MD5 hash for a specific string input */
|
|
7
|
-
export function md5(s: string): string {
|
|
8
|
-
return hex(md51(s));
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/* this function is much faster,
|
|
12
|
-
so if possible we use it. Some IEs
|
|
13
|
-
are the only ones I know of that
|
|
14
|
-
need the idiotic second function,
|
|
15
|
-
generated by an if clause. */
|
|
16
|
-
|
|
17
|
-
var add32 = (a, b) => {
|
|
18
|
-
return (a + b) & 0xFFFFFFFF;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
function md5cycle(x, k) {
|
|
22
|
-
var a = x[0], b = x[1], c = x[2], d = x[3];
|
|
23
|
-
|
|
24
|
-
a = ff(a, b, c, d, k[0], 7, -680876936);
|
|
25
|
-
d = ff(d, a, b, c, k[1], 12, -389564586);
|
|
26
|
-
c = ff(c, d, a, b, k[2], 17, 606105819);
|
|
27
|
-
b = ff(b, c, d, a, k[3], 22, -1044525330);
|
|
28
|
-
a = ff(a, b, c, d, k[4], 7, -176418897);
|
|
29
|
-
d = ff(d, a, b, c, k[5], 12, 1200080426);
|
|
30
|
-
c = ff(c, d, a, b, k[6], 17, -1473231341);
|
|
31
|
-
b = ff(b, c, d, a, k[7], 22, -45705983);
|
|
32
|
-
a = ff(a, b, c, d, k[8], 7, 1770035416);
|
|
33
|
-
d = ff(d, a, b, c, k[9], 12, -1958414417);
|
|
34
|
-
c = ff(c, d, a, b, k[10], 17, -42063);
|
|
35
|
-
b = ff(b, c, d, a, k[11], 22, -1990404162);
|
|
36
|
-
a = ff(a, b, c, d, k[12], 7, 1804603682);
|
|
37
|
-
d = ff(d, a, b, c, k[13], 12, -40341101);
|
|
38
|
-
c = ff(c, d, a, b, k[14], 17, -1502002290);
|
|
39
|
-
b = ff(b, c, d, a, k[15], 22, 1236535329);
|
|
40
|
-
|
|
41
|
-
a = gg(a, b, c, d, k[1], 5, -165796510);
|
|
42
|
-
d = gg(d, a, b, c, k[6], 9, -1069501632);
|
|
43
|
-
c = gg(c, d, a, b, k[11], 14, 643717713);
|
|
44
|
-
b = gg(b, c, d, a, k[0], 20, -373897302);
|
|
45
|
-
a = gg(a, b, c, d, k[5], 5, -701558691);
|
|
46
|
-
d = gg(d, a, b, c, k[10], 9, 38016083);
|
|
47
|
-
c = gg(c, d, a, b, k[15], 14, -660478335);
|
|
48
|
-
b = gg(b, c, d, a, k[4], 20, -405537848);
|
|
49
|
-
a = gg(a, b, c, d, k[9], 5, 568446438);
|
|
50
|
-
d = gg(d, a, b, c, k[14], 9, -1019803690);
|
|
51
|
-
c = gg(c, d, a, b, k[3], 14, -187363961);
|
|
52
|
-
b = gg(b, c, d, a, k[8], 20, 1163531501);
|
|
53
|
-
a = gg(a, b, c, d, k[13], 5, -1444681467);
|
|
54
|
-
d = gg(d, a, b, c, k[2], 9, -51403784);
|
|
55
|
-
c = gg(c, d, a, b, k[7], 14, 1735328473);
|
|
56
|
-
b = gg(b, c, d, a, k[12], 20, -1926607734);
|
|
57
|
-
|
|
58
|
-
a = hh(a, b, c, d, k[5], 4, -378558);
|
|
59
|
-
d = hh(d, a, b, c, k[8], 11, -2022574463);
|
|
60
|
-
c = hh(c, d, a, b, k[11], 16, 1839030562);
|
|
61
|
-
b = hh(b, c, d, a, k[14], 23, -35309556);
|
|
62
|
-
a = hh(a, b, c, d, k[1], 4, -1530992060);
|
|
63
|
-
d = hh(d, a, b, c, k[4], 11, 1272893353);
|
|
64
|
-
c = hh(c, d, a, b, k[7], 16, -155497632);
|
|
65
|
-
b = hh(b, c, d, a, k[10], 23, -1094730640);
|
|
66
|
-
a = hh(a, b, c, d, k[13], 4, 681279174);
|
|
67
|
-
d = hh(d, a, b, c, k[0], 11, -358537222);
|
|
68
|
-
c = hh(c, d, a, b, k[3], 16, -722521979);
|
|
69
|
-
b = hh(b, c, d, a, k[6], 23, 76029189);
|
|
70
|
-
a = hh(a, b, c, d, k[9], 4, -640364487);
|
|
71
|
-
d = hh(d, a, b, c, k[12], 11, -421815835);
|
|
72
|
-
c = hh(c, d, a, b, k[15], 16, 530742520);
|
|
73
|
-
b = hh(b, c, d, a, k[2], 23, -995338651);
|
|
74
|
-
|
|
75
|
-
a = ii(a, b, c, d, k[0], 6, -198630844);
|
|
76
|
-
d = ii(d, a, b, c, k[7], 10, 1126891415);
|
|
77
|
-
c = ii(c, d, a, b, k[14], 15, -1416354905);
|
|
78
|
-
b = ii(b, c, d, a, k[5], 21, -57434055);
|
|
79
|
-
a = ii(a, b, c, d, k[12], 6, 1700485571);
|
|
80
|
-
d = ii(d, a, b, c, k[3], 10, -1894986606);
|
|
81
|
-
c = ii(c, d, a, b, k[10], 15, -1051523);
|
|
82
|
-
b = ii(b, c, d, a, k[1], 21, -2054922799);
|
|
83
|
-
a = ii(a, b, c, d, k[8], 6, 1873313359);
|
|
84
|
-
d = ii(d, a, b, c, k[15], 10, -30611744);
|
|
85
|
-
c = ii(c, d, a, b, k[6], 15, -1560198380);
|
|
86
|
-
b = ii(b, c, d, a, k[13], 21, 1309151649);
|
|
87
|
-
a = ii(a, b, c, d, k[4], 6, -145523070);
|
|
88
|
-
d = ii(d, a, b, c, k[11], 10, -1120210379);
|
|
89
|
-
c = ii(c, d, a, b, k[2], 15, 718787259);
|
|
90
|
-
b = ii(b, c, d, a, k[9], 21, -343485551);
|
|
91
|
-
|
|
92
|
-
x[0] = add32(a, x[0]);
|
|
93
|
-
x[1] = add32(b, x[1]);
|
|
94
|
-
x[2] = add32(c, x[2]);
|
|
95
|
-
x[3] = add32(d, x[3]);
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function cmn(q, a, b, x, s, t) {
|
|
100
|
-
a = add32(add32(a, q), add32(x, t));
|
|
101
|
-
return add32((a << s) | (a >>> (32 - s)), b);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function ff(a, b, c, d, x, s, t) {
|
|
105
|
-
return cmn((b & c) | ((~b) & d), a, b, x, s, t);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function gg(a, b, c, d, x, s, t) {
|
|
109
|
-
return cmn((b & d) | (c & (~d)), a, b, x, s, t);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function hh(a, b, c, d, x, s, t) {
|
|
113
|
-
return cmn(b ^ c ^ d, a, b, x, s, t);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function ii(a, b, c, d, x, s, t) {
|
|
117
|
-
return cmn(c ^ (b | (~d)), a, b, x, s, t);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function md51(s) {
|
|
121
|
-
//var txt = '';
|
|
122
|
-
var n = s.length,
|
|
123
|
-
state = [1732584193, -271733879, -1732584194, 271733878], i;
|
|
124
|
-
for (i = 64; i <= s.length; i += 64) {
|
|
125
|
-
md5cycle(state, md5blk(s.substring(i - 64, i)));
|
|
126
|
-
}
|
|
127
|
-
s = s.substring(i - 64);
|
|
128
|
-
var tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
129
|
-
for (i = 0; i < s.length; i++)
|
|
130
|
-
tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3);
|
|
131
|
-
tail[i >> 2] |= 0x80 << ((i % 4) << 3);
|
|
132
|
-
if (i > 55) {
|
|
133
|
-
md5cycle(state, tail);
|
|
134
|
-
for (i = 0; i < 16; i++) tail[i] = 0;
|
|
135
|
-
}
|
|
136
|
-
tail[14] = n * 8;
|
|
137
|
-
md5cycle(state, tail);
|
|
138
|
-
return state;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/* there needs to be support for Unicode here,
|
|
142
|
-
* unless we pretend that we can redefine the MD-5
|
|
143
|
-
* algorithm for multi-byte characters (perhaps
|
|
144
|
-
* by adding every four 16-bit characters and
|
|
145
|
-
* shortening the sum to 32 bits). Otherwise
|
|
146
|
-
* I suggest performing MD-5 as if every character
|
|
147
|
-
* was two bytes--e.g., 0040 0025 = @%--but then
|
|
148
|
-
* how will an ordinary MD-5 sum be matched?
|
|
149
|
-
* There is no way to standardize text to something
|
|
150
|
-
* like UTF-8 before transformation; speed cost is
|
|
151
|
-
* utterly prohibitive. The JavaScript standard
|
|
152
|
-
* itself needs to look at this: it should start
|
|
153
|
-
* providing access to strings as preformed UTF-8
|
|
154
|
-
* 8-bit unsigned value arrays.
|
|
155
|
-
*/
|
|
156
|
-
function md5blk(s) { /* I figured global was faster. */
|
|
157
|
-
var md5blks = [], i; /* Andy King said do it this way. */
|
|
158
|
-
for (i = 0; i < 64; i += 4) {
|
|
159
|
-
md5blks[i >> 2] = s.charCodeAt(i)
|
|
160
|
-
+ (s.charCodeAt(i + 1) << 8)
|
|
161
|
-
+ (s.charCodeAt(i + 2) << 16)
|
|
162
|
-
+ (s.charCodeAt(i + 3) << 24);
|
|
163
|
-
}
|
|
164
|
-
return md5blks;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
var hex_chr = '0123456789abcdef'.split('');
|
|
168
|
-
|
|
169
|
-
function rhex(n) {
|
|
170
|
-
var s = '', j = 0;
|
|
171
|
-
for (; j < 4; j++)
|
|
172
|
-
s += hex_chr[(n >> (j * 8 + 4)) & 0x0F]
|
|
173
|
-
+ hex_chr[(n >> (j * 8)) & 0x0F];
|
|
174
|
-
return s;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function hex(x) {
|
|
178
|
-
for (var i = 0; i < x.length; i++)
|
|
179
|
-
x[i] = rhex(x[i]);
|
|
180
|
-
return x.join('');
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (md5('hello') !== '5d41402abc4b2a76b9719d911017c592') {
|
|
184
|
-
//slower one, for IE only
|
|
185
|
-
add32 = (x, y) => {
|
|
186
|
-
var lsw = (x & 0xFFFF) + (y & 0xFFFF),
|
|
187
|
-
msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
|
188
|
-
return (msw << 16) | (lsw & 0xFFFF);
|
|
189
|
-
};
|
|
190
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import assert from 'assert/strict';
|
|
2
|
-
import test from 'node:test';
|
|
3
|
-
import { objectsEqual } from './objects';
|
|
4
|
-
|
|
5
|
-
test('objectsEqual', async t => {
|
|
6
|
-
let now = new Date();
|
|
7
|
-
let next = new Date(now.getTime() + 10000);//add a second
|
|
8
|
-
assert.strictEqual(objectsEqual(1.42, 1.42), true);
|
|
9
|
-
assert.strictEqual(objectsEqual(now, now), true);
|
|
10
|
-
assert.strictEqual(objectsEqual(now, next), false);
|
|
11
|
-
assert.strictEqual(objectsEqual("hello", "bye"), false);
|
|
12
|
-
assert.strictEqual(objectsEqual(() => { console.log(1); }, () => { console.log(1); }), true);
|
|
13
|
-
assert.strictEqual(objectsEqual(() => { console.log(1); }, () => { console.log(2); }), false);
|
|
14
|
-
assert.strictEqual(objectsEqual(
|
|
15
|
-
{ id: 1, name: "test", complex: { cid: 4, foo: () => console.log(1) }, nested: { nid: 4, complex: { ncid: 5, time: now } } },
|
|
16
|
-
{ id: 1, name: "test", complex: { cid: 4, foo: () => console.log(1) }, nested: { nid: 4, complex: { ncid: 5, time: now } } }),
|
|
17
|
-
true);
|
|
18
|
-
assert.strictEqual(objectsEqual(
|
|
19
|
-
{ id: 1, name: "test", complex: { cid: 4, foo: () => console.log(1) }, nested: { nid: 4, complex: { ncid: 5, time: now } } },
|
|
20
|
-
{ id: 1, name: "test", complex: { cid: 4, foo: () => console.log(1) }, nested: { nid: 4, complex: { ncid: 5, time: next } } }),
|
|
21
|
-
false);
|
|
22
|
-
assert.strictEqual(objectsEqual(
|
|
23
|
-
{ id: 1, name: "test", complex: { cid: 4, foo: () => console.log(1) }, nested: { nid: 4, complex: { ncid: 5, time: now } } },
|
|
24
|
-
{ id: 1, name: "test", complex: { cid: 4, foo: () => console.log(1) }, nested: { nid: 4, complex: { ncid: 5, time: next } } },
|
|
25
|
-
["time"]),
|
|
26
|
-
true);
|
|
27
|
-
});
|