@sendbird/uikit-utils 2.2.0 → 2.3.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/lib/commonjs/hooks/react-native.js +56 -0
- package/lib/commonjs/hooks/react-native.js.map +1 -0
- package/lib/commonjs/index.js +28 -20
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/shared/index.js +74 -0
- package/lib/commonjs/shared/index.js.map +1 -0
- package/lib/module/hooks/react-native.js +39 -0
- package/lib/module/hooks/react-native.js.map +1 -0
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/shared/index.js +57 -0
- package/lib/module/shared/index.js.map +1 -0
- package/lib/typescript/src/hooks/react-native.d.ts +12 -0
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/shared/index.d.ts +26 -0
- package/package.json +3 -2
- package/src/hooks/react-native.ts +56 -0
- package/src/index.ts +3 -2
- package/src/shared/index.ts +56 -0
- package/lib/commonjs/shared/conditionChaining.js +0 -15
- package/lib/commonjs/shared/conditionChaining.js.map +0 -1
- package/lib/commonjs/shared/replace.js +0 -14
- package/lib/commonjs/shared/replace.js.map +0 -1
- package/lib/module/shared/conditionChaining.js +0 -7
- package/lib/module/shared/conditionChaining.js.map +0 -1
- package/lib/module/shared/replace.js +0 -6
- package/lib/module/shared/replace.js.map +0 -1
- package/lib/typescript/src/shared/conditionChaining.d.ts +0 -2
- package/lib/typescript/src/shared/replace.d.ts +0 -2
- package/src/shared/conditionChaining.ts +0 -6
- package/src/shared/replace.ts +0 -5
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useSafeAreaPadding = exports.useAppState = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
var _reactNative = require("react-native");
|
|
11
|
+
|
|
12
|
+
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
|
|
13
|
+
|
|
14
|
+
const edgePaddingMap = {
|
|
15
|
+
left: 'paddingLeft',
|
|
16
|
+
right: 'paddingRight',
|
|
17
|
+
top: 'paddingTop',
|
|
18
|
+
bottom: 'paddingBottom'
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const useSafeAreaPadding = edges => {
|
|
22
|
+
const safeAreaInsets = (0, _reactNativeSafeAreaContext.useSafeAreaInsets)();
|
|
23
|
+
return (0, _react.useMemo)(() => {
|
|
24
|
+
return edges.reduce((map, edge) => {
|
|
25
|
+
const paddingKey = edgePaddingMap[edge];
|
|
26
|
+
map[paddingKey] = safeAreaInsets[edge];
|
|
27
|
+
return map;
|
|
28
|
+
}, {});
|
|
29
|
+
}, edges);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.useSafeAreaPadding = useSafeAreaPadding;
|
|
33
|
+
|
|
34
|
+
const useAppState = (type, listener) => {
|
|
35
|
+
const callbackRef = (0, _react.useRef)(listener);
|
|
36
|
+
callbackRef.current = listener;
|
|
37
|
+
(0, _react.useEffect)(() => {
|
|
38
|
+
const eventListener = state => callbackRef.current(state);
|
|
39
|
+
|
|
40
|
+
const subscriber = _reactNative.AppState.addEventListener(type, eventListener);
|
|
41
|
+
|
|
42
|
+
return () => {
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
if (subscriber !== null && subscriber !== void 0 && subscriber.remove) {
|
|
45
|
+
subscriber.remove();
|
|
46
|
+
} // @ts-ignore
|
|
47
|
+
else if (_reactNative.AppState.removeEventListener) {
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
_reactNative.AppState.removeEventListener(type, eventListener);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}, []);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
exports.useAppState = useAppState;
|
|
56
|
+
//# sourceMappingURL=react-native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["edgePaddingMap","left","right","top","bottom","useSafeAreaPadding","edges","safeAreaInsets","useSafeAreaInsets","useMemo","reduce","map","edge","paddingKey","useAppState","type","listener","callbackRef","useRef","current","useEffect","eventListener","state","subscriber","AppState","addEventListener","remove","removeEventListener"],"sources":["react-native.ts"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\nimport { AppState, AppStateEvent, AppStateStatus } from 'react-native';\nimport { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';\n\ntype EdgePaddingMap = {\n left: 'paddingLeft';\n right: 'paddingRight';\n top: 'paddingTop';\n bottom: 'paddingBottom';\n};\nconst edgePaddingMap: EdgePaddingMap = {\n left: 'paddingLeft',\n right: 'paddingRight',\n top: 'paddingTop',\n bottom: 'paddingBottom',\n};\n\nexport const useSafeAreaPadding = <\n T extends keyof EdgeInsets,\n Result extends { [key in EdgePaddingMap[T]]: EdgeInsets[T] },\n>(\n edges: T[],\n): Result => {\n const safeAreaInsets = useSafeAreaInsets();\n return useMemo(() => {\n return edges.reduce((map, edge) => {\n const paddingKey = edgePaddingMap[edge];\n map[paddingKey] = safeAreaInsets[edge];\n return map;\n }, {} as { [key in EdgePaddingMap[T]]: EdgeInsets[T] });\n }, edges) as Result;\n};\n\ntype AppStateListener = (status: AppStateStatus) => void;\n\nexport const useAppState = (type: AppStateEvent, listener: AppStateListener) => {\n const callbackRef = useRef<AppStateListener>(listener);\n callbackRef.current = listener;\n\n useEffect(() => {\n const eventListener = (state: AppStateStatus) => callbackRef.current(state);\n const subscriber = AppState.addEventListener(type, eventListener);\n\n return () => {\n // @ts-ignore\n if (subscriber?.remove) {\n subscriber.remove();\n }\n // @ts-ignore\n else if (AppState.removeEventListener) {\n // @ts-ignore\n AppState.removeEventListener(type, eventListener);\n }\n };\n }, []);\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAQA,MAAMA,cAA8B,GAAG;EACrCC,IAAI,EAAE,aAD+B;EAErCC,KAAK,EAAE,cAF8B;EAGrCC,GAAG,EAAE,YAHgC;EAIrCC,MAAM,EAAE;AAJ6B,CAAvC;;AAOO,MAAMC,kBAAkB,GAI7BC,KAJgC,IAKrB;EACX,MAAMC,cAAc,GAAG,IAAAC,6CAAA,GAAvB;EACA,OAAO,IAAAC,cAAA,EAAQ,MAAM;IACnB,OAAOH,KAAK,CAACI,MAAN,CAAa,CAACC,GAAD,EAAMC,IAAN,KAAe;MACjC,MAAMC,UAAU,GAAGb,cAAc,CAACY,IAAD,CAAjC;MACAD,GAAG,CAACE,UAAD,CAAH,GAAkBN,cAAc,CAACK,IAAD,CAAhC;MACA,OAAOD,GAAP;IACD,CAJM,EAIJ,EAJI,CAAP;EAKD,CANM,EAMJL,KANI,CAAP;AAOD,CAdM;;;;AAkBA,MAAMQ,WAAW,GAAG,CAACC,IAAD,EAAsBC,QAAtB,KAAqD;EAC9E,MAAMC,WAAW,GAAG,IAAAC,aAAA,EAAyBF,QAAzB,CAApB;EACAC,WAAW,CAACE,OAAZ,GAAsBH,QAAtB;EAEA,IAAAI,gBAAA,EAAU,MAAM;IACd,MAAMC,aAAa,GAAIC,KAAD,IAA2BL,WAAW,CAACE,OAAZ,CAAoBG,KAApB,CAAjD;;IACA,MAAMC,UAAU,GAAGC,qBAAA,CAASC,gBAAT,CAA0BV,IAA1B,EAAgCM,aAAhC,CAAnB;;IAEA,OAAO,MAAM;MACX;MACA,IAAIE,UAAJ,aAAIA,UAAJ,eAAIA,UAAU,CAAEG,MAAhB,EAAwB;QACtBH,UAAU,CAACG,MAAX;MACD,CAFD,CAGA;MAHA,KAIK,IAAIF,qBAAA,CAASG,mBAAb,EAAkC;QACrC;QACAH,qBAAA,CAASG,mBAAT,CAA6BZ,IAA7B,EAAmCM,aAAnC;MACD;IACF,CAVD;EAWD,CAfD,EAeG,EAfH;AAgBD,CApBM"}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -15,7 +15,6 @@ var _exportNames = {
|
|
|
15
15
|
arrayToMap: true,
|
|
16
16
|
arrayToMapWithGetter: true,
|
|
17
17
|
createPubSub: true,
|
|
18
|
-
conditionChaining: true,
|
|
19
18
|
urlRegexStrict: true,
|
|
20
19
|
urlRegexRough: true,
|
|
21
20
|
newLineRegex: true,
|
|
@@ -30,8 +29,7 @@ var _exportNames = {
|
|
|
30
29
|
phoneRegex: true,
|
|
31
30
|
replaceWithRegex: true,
|
|
32
31
|
createMentionTemplateRegex: true,
|
|
33
|
-
BufferedRequest: true
|
|
34
|
-
replace: true
|
|
32
|
+
BufferedRequest: true
|
|
35
33
|
};
|
|
36
34
|
exports.ASYNC_NOOP = void 0;
|
|
37
35
|
Object.defineProperty(exports, "BufferedRequest", {
|
|
@@ -65,12 +63,6 @@ Object.defineProperty(exports, "audioExtRegex", {
|
|
|
65
63
|
return _regex.audioExtRegex;
|
|
66
64
|
}
|
|
67
65
|
});
|
|
68
|
-
Object.defineProperty(exports, "conditionChaining", {
|
|
69
|
-
enumerable: true,
|
|
70
|
-
get: function () {
|
|
71
|
-
return _conditionChaining.default;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
66
|
Object.defineProperty(exports, "createMentionTemplateRegex", {
|
|
75
67
|
enumerable: true,
|
|
76
68
|
get: function () {
|
|
@@ -126,12 +118,6 @@ Object.defineProperty(exports, "phoneRegex", {
|
|
|
126
118
|
return _regex.phoneRegex;
|
|
127
119
|
}
|
|
128
120
|
});
|
|
129
|
-
Object.defineProperty(exports, "replace", {
|
|
130
|
-
enumerable: true,
|
|
131
|
-
get: function () {
|
|
132
|
-
return _replace.default;
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
121
|
Object.defineProperty(exports, "replaceUrlAsComponents", {
|
|
136
122
|
enumerable: true,
|
|
137
123
|
get: function () {
|
|
@@ -170,13 +156,23 @@ var _arrayToMap = _interopRequireWildcard(require("./shared/arrayToMap"));
|
|
|
170
156
|
|
|
171
157
|
var _pubsub = require("./shared/pubsub");
|
|
172
158
|
|
|
173
|
-
var _conditionChaining = _interopRequireDefault(require("./shared/conditionChaining"));
|
|
174
|
-
|
|
175
159
|
var _regex = require("./shared/regex");
|
|
176
160
|
|
|
177
161
|
var _bufferedRequest = require("./shared/bufferedRequest");
|
|
178
162
|
|
|
179
|
-
var
|
|
163
|
+
var _shared = require("./shared");
|
|
164
|
+
|
|
165
|
+
Object.keys(_shared).forEach(function (key) {
|
|
166
|
+
if (key === "default" || key === "__esModule") return;
|
|
167
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
168
|
+
if (key in exports && exports[key] === _shared[key]) return;
|
|
169
|
+
Object.defineProperty(exports, key, {
|
|
170
|
+
enumerable: true,
|
|
171
|
+
get: function () {
|
|
172
|
+
return _shared[key];
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
});
|
|
180
176
|
|
|
181
177
|
var _hooks = require("./hooks");
|
|
182
178
|
|
|
@@ -192,6 +188,20 @@ Object.keys(_hooks).forEach(function (key) {
|
|
|
192
188
|
});
|
|
193
189
|
});
|
|
194
190
|
|
|
191
|
+
var _reactNative = require("./hooks/react-native");
|
|
192
|
+
|
|
193
|
+
Object.keys(_reactNative).forEach(function (key) {
|
|
194
|
+
if (key === "default" || key === "__esModule") return;
|
|
195
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
196
|
+
if (key in exports && exports[key] === _reactNative[key]) return;
|
|
197
|
+
Object.defineProperty(exports, key, {
|
|
198
|
+
enumerable: true,
|
|
199
|
+
get: function () {
|
|
200
|
+
return _reactNative[key];
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
195
205
|
var _groupChannel = require("./ui-format/groupChannel");
|
|
196
206
|
|
|
197
207
|
Object.keys(_groupChannel).forEach(function (key) {
|
|
@@ -276,8 +286,6 @@ Object.keys(_user).forEach(function (key) {
|
|
|
276
286
|
});
|
|
277
287
|
});
|
|
278
288
|
|
|
279
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
280
|
-
|
|
281
289
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
282
290
|
|
|
283
291
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NOOP","ASYNC_NOOP","PASS","val","toMegabyte","byte","isFunction","param","SBErrorCode","NON_AUTHORIZED","SBErrorMessage","ACL"],"sources":["index.ts"],"sourcesContent":["export { Logger } from './shared/logger';\nexport { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';\nexport { createPubSub } from './shared/pubsub';\nexport {
|
|
1
|
+
{"version":3,"names":["NOOP","ASYNC_NOOP","PASS","val","toMegabyte","byte","isFunction","param","SBErrorCode","NON_AUTHORIZED","SBErrorMessage","ACL"],"sources":["index.ts"],"sourcesContent":["export { Logger } from './shared/logger';\nexport { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';\nexport { createPubSub } from './shared/pubsub';\nexport {\n urlRegexStrict,\n urlRegexRough,\n newLineRegex,\n audioExtRegex,\n videoExtRegex,\n imageExtRegex,\n getFileType,\n getFileExtension,\n replaceUrlAsComponents,\n normalizeFileName,\n emailRegex,\n phoneRegex,\n replaceWithRegex,\n createMentionTemplateRegex,\n} from './shared/regex';\nexport { BufferedRequest } from './shared/bufferedRequest';\n\nexport * from './shared';\n\nexport * from './hooks';\nexport * from './hooks/react-native';\nexport * from './ui-format/groupChannel';\nexport * from './ui-format/common';\nexport * from './sendbird/channel';\nexport * from './sendbird/message';\nexport * from './sendbird/attrs';\nexport * from './sendbird/user';\n\nexport const NOOP: () => void = () => void 0;\nexport const ASYNC_NOOP = async () => void 0;\nexport const PASS = <T>(val: T) => val;\nexport const toMegabyte = (byte: number) => byte / 1024 / 1024;\nexport const isFunction = <T>(param?: T): param is NonNullable<T> => typeof param === 'function';\nexport const SBErrorCode = {\n NON_AUTHORIZED: 400108,\n};\nexport const SBErrorMessage = {\n ACL:\n 'Sendbird provides various access control options when using the Chat SDK.\\n' +\n 'By default, the Allow retrieving user list attribute is turned on to facilitate creating sample apps.\\n' +\n 'However, this may grant access to unwanted data or operations, leading to potential security concerns.\\n' +\n 'To manage your access control settings, you can turn on or off each setting on Sendbird Dashboard.',\n};\n\nexport type {\n UserStruct,\n FilterByValueType,\n UnionToIntersection,\n OmittedValues,\n PartialDeep,\n Optional,\n ContextValue,\n SendbirdMessage,\n SendbirdChatSDK,\n SendbirdChannel,\n SendbirdBaseChannel,\n SendbirdGroupChannel,\n SendbirdOpenChannel,\n SendbirdUser,\n SendbirdMember,\n SendbirdBaseMessage,\n SendbirdUserMessage,\n SendbirdFileMessage,\n SendbirdAdminMessage,\n SendbirdGroupChannelCreateParams,\n SendbirdFileMessageCreateParams,\n SendbirdUserMessageCreateParams,\n SendbirdError,\n SendbirdMessageCollection,\n SendbirdGroupChannelCollection,\n NotificationFiles,\n NotificationMentionedUsers,\n NotificationTranslations,\n PartialNullable,\n SendbirdDataPayload,\n SendbirdPreviousMessageListQuery,\n SendbirdSendableMessage,\n SendbirdGroupChannelListQuery,\n SendbirdGroupChannelUpdateParams,\n SendbirdUserMessageUpdateParams,\n SendbirdFileMessageUpdateParams,\n SendbirdUserUpdateParams,\n SendbirdRestrictedUser,\n SendbirdReaction,\n SendbirdEmojiContainer,\n SendbirdEmoji,\n SendbirdEmojiCategory,\n} from './types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAgBA;;AAEA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAEA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;;;;;AAEO,MAAMA,IAAgB,GAAG,MAAM,KAAK,CAApC;;;;AACA,MAAMC,UAAU,GAAG,YAAY,KAAK,CAApC;;;;AACA,MAAMC,IAAI,GAAOC,GAAJ,IAAeA,GAA5B;;;;AACA,MAAMC,UAAU,GAAIC,IAAD,IAAkBA,IAAI,GAAG,IAAP,GAAc,IAAnD;;;;AACA,MAAMC,UAAU,GAAOC,KAAJ,IAA2C,OAAOA,KAAP,KAAiB,UAA/E;;;AACA,MAAMC,WAAW,GAAG;EACzBC,cAAc,EAAE;AADS,CAApB;;AAGA,MAAMC,cAAc,GAAG;EAC5BC,GAAG,EACD,gFACA,yGADA,GAEA,0GAFA,GAGA;AAL0B,CAAvB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.conditionChaining = conditionChaining;
|
|
7
|
+
exports.getDownscaleSize = getDownscaleSize;
|
|
8
|
+
exports.hash = hash;
|
|
9
|
+
exports.isImage = isImage;
|
|
10
|
+
exports.replace = replace;
|
|
11
|
+
exports.shouldCompressImage = shouldCompressImage;
|
|
12
|
+
|
|
13
|
+
var _regex = require("./regex");
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Converts a given string to a hashed string.
|
|
17
|
+
* */
|
|
18
|
+
function hash(str) {
|
|
19
|
+
return String(Math.abs(str.split('').reduce((a, c) => (a << 5) - a + c.charCodeAt(0) | 0, 0)));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Replace a specific range of text in the string with another text.
|
|
23
|
+
* */
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function replace(str, start, end, text) {
|
|
27
|
+
return str.slice(0, start) + text + str.slice(end);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Returns the value corresponding to the first true index of a given condition array.
|
|
31
|
+
* */
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
function conditionChaining(conditions, values) {
|
|
35
|
+
const idx = conditions.findIndex(state => Boolean(state));
|
|
36
|
+
return idx > -1 ? values[idx] : values[values.length - 1];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Calculates the downscale size.
|
|
40
|
+
* */
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
function getDownscaleSize(origin, resizing) {
|
|
44
|
+
let ratio;
|
|
45
|
+
const maxWidth = resizing.width || origin.width,
|
|
46
|
+
maxHeight = resizing.height || origin.height;
|
|
47
|
+
|
|
48
|
+
if (origin.width <= maxWidth && origin.height <= maxHeight) {
|
|
49
|
+
ratio = 1;
|
|
50
|
+
} else if (origin.width > maxWidth && origin.height <= maxHeight) {
|
|
51
|
+
ratio = maxWidth / origin.width;
|
|
52
|
+
} else if (origin.width <= maxWidth && origin.height > maxHeight) {
|
|
53
|
+
ratio = maxHeight / origin.height;
|
|
54
|
+
} else {
|
|
55
|
+
ratio = Math.max(maxWidth / origin.width, maxHeight / origin.height);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
width: origin.width * ratio,
|
|
60
|
+
height: origin.height * ratio
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function isImage(filePath, mimeType) {
|
|
65
|
+
const type = (0, _regex.getFileType)(mimeType || (0, _regex.getFileExtension)(filePath));
|
|
66
|
+
return type === 'image';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function shouldCompressImage(filePath) {
|
|
70
|
+
let compressionEnabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
71
|
+
const extension = (0, _regex.getFileExtension)(filePath);
|
|
72
|
+
return Boolean(extension.match(/jpg|jpeg|png/i) && compressionEnabled);
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["hash","str","String","Math","abs","split","reduce","a","c","charCodeAt","replace","start","end","text","slice","conditionChaining","conditions","values","idx","findIndex","state","Boolean","length","getDownscaleSize","origin","resizing","ratio","maxWidth","width","maxHeight","height","max","isImage","filePath","mimeType","type","getFileType","getFileExtension","shouldCompressImage","compressionEnabled","extension","match"],"sources":["index.ts"],"sourcesContent":["import { getFileExtension, getFileType } from './regex';\n\n/**\n * Converts a given string to a hashed string.\n * */\nexport function hash(str: string) {\n return String(Math.abs(str.split('').reduce((a, c) => ((a << 5) - a + c.charCodeAt(0)) | 0, 0)));\n}\n\n/**\n * Replace a specific range of text in the string with another text.\n * */\nexport function replace(str: string, start: number, end: number, text: string) {\n return str.slice(0, start) + text + str.slice(end);\n}\n\n/**\n * Returns the value corresponding to the first true index of a given condition array.\n * */\nexport function conditionChaining<T, V>(conditions: T[], values: V[]) {\n const idx = conditions.findIndex((state) => Boolean(state));\n return idx > -1 ? values[idx] : values[values.length - 1];\n}\n\n/**\n * Calculates the downscale size.\n * */\ntype Size = { width: number; height: number };\nexport function getDownscaleSize(origin: Size, resizing: Partial<Size>) {\n let ratio;\n\n const maxWidth = resizing.width || origin.width,\n maxHeight = resizing.height || origin.height;\n\n if (origin.width <= maxWidth && origin.height <= maxHeight) {\n ratio = 1;\n } else if (origin.width > maxWidth && origin.height <= maxHeight) {\n ratio = maxWidth / origin.width;\n } else if (origin.width <= maxWidth && origin.height > maxHeight) {\n ratio = maxHeight / origin.height;\n } else {\n ratio = Math.max(maxWidth / origin.width, maxHeight / origin.height);\n }\n\n return { width: origin.width * ratio, height: origin.height * ratio };\n}\n\nexport function isImage(filePath: string, mimeType?: string) {\n const type = getFileType(mimeType || getFileExtension(filePath));\n return type === 'image';\n}\n\nexport function shouldCompressImage(filePath: string, compressionEnabled = true) {\n const extension = getFileExtension(filePath);\n return Boolean(extension.match(/jpg|jpeg|png/i) && compressionEnabled);\n}\n"],"mappings":";;;;;;;;;;;;AAAA;;AAEA;AACA;AACA;AACO,SAASA,IAAT,CAAcC,GAAd,EAA2B;EAChC,OAAOC,MAAM,CAACC,IAAI,CAACC,GAAL,CAASH,GAAG,CAACI,KAAJ,CAAU,EAAV,EAAcC,MAAd,CAAqB,CAACC,CAAD,EAAIC,CAAJ,KAAW,CAACD,CAAC,IAAI,CAAN,IAAWA,CAAX,GAAeC,CAAC,CAACC,UAAF,CAAa,CAAb,CAAhB,GAAmC,CAAlE,EAAqE,CAArE,CAAT,CAAD,CAAb;AACD;AAED;AACA;AACA;;;AACO,SAASC,OAAT,CAAiBT,GAAjB,EAA8BU,KAA9B,EAA6CC,GAA7C,EAA0DC,IAA1D,EAAwE;EAC7E,OAAOZ,GAAG,CAACa,KAAJ,CAAU,CAAV,EAAaH,KAAb,IAAsBE,IAAtB,GAA6BZ,GAAG,CAACa,KAAJ,CAAUF,GAAV,CAApC;AACD;AAED;AACA;AACA;;;AACO,SAASG,iBAAT,CAAiCC,UAAjC,EAAkDC,MAAlD,EAA+D;EACpE,MAAMC,GAAG,GAAGF,UAAU,CAACG,SAAX,CAAsBC,KAAD,IAAWC,OAAO,CAACD,KAAD,CAAvC,CAAZ;EACA,OAAOF,GAAG,GAAG,CAAC,CAAP,GAAWD,MAAM,CAACC,GAAD,CAAjB,GAAyBD,MAAM,CAACA,MAAM,CAACK,MAAP,GAAgB,CAAjB,CAAtC;AACD;AAED;AACA;AACA;;;AAEO,SAASC,gBAAT,CAA0BC,MAA1B,EAAwCC,QAAxC,EAAiE;EACtE,IAAIC,KAAJ;EAEA,MAAMC,QAAQ,GAAGF,QAAQ,CAACG,KAAT,IAAkBJ,MAAM,CAACI,KAA1C;EAAA,MACEC,SAAS,GAAGJ,QAAQ,CAACK,MAAT,IAAmBN,MAAM,CAACM,MADxC;;EAGA,IAAIN,MAAM,CAACI,KAAP,IAAgBD,QAAhB,IAA4BH,MAAM,CAACM,MAAP,IAAiBD,SAAjD,EAA4D;IAC1DH,KAAK,GAAG,CAAR;EACD,CAFD,MAEO,IAAIF,MAAM,CAACI,KAAP,GAAeD,QAAf,IAA2BH,MAAM,CAACM,MAAP,IAAiBD,SAAhD,EAA2D;IAChEH,KAAK,GAAGC,QAAQ,GAAGH,MAAM,CAACI,KAA1B;EACD,CAFM,MAEA,IAAIJ,MAAM,CAACI,KAAP,IAAgBD,QAAhB,IAA4BH,MAAM,CAACM,MAAP,GAAgBD,SAAhD,EAA2D;IAChEH,KAAK,GAAGG,SAAS,GAAGL,MAAM,CAACM,MAA3B;EACD,CAFM,MAEA;IACLJ,KAAK,GAAGvB,IAAI,CAAC4B,GAAL,CAASJ,QAAQ,GAAGH,MAAM,CAACI,KAA3B,EAAkCC,SAAS,GAAGL,MAAM,CAACM,MAArD,CAAR;EACD;;EAED,OAAO;IAAEF,KAAK,EAAEJ,MAAM,CAACI,KAAP,GAAeF,KAAxB;IAA+BI,MAAM,EAAEN,MAAM,CAACM,MAAP,GAAgBJ;EAAvD,CAAP;AACD;;AAEM,SAASM,OAAT,CAAiBC,QAAjB,EAAmCC,QAAnC,EAAsD;EAC3D,MAAMC,IAAI,GAAG,IAAAC,kBAAA,EAAYF,QAAQ,IAAI,IAAAG,uBAAA,EAAiBJ,QAAjB,CAAxB,CAAb;EACA,OAAOE,IAAI,KAAK,OAAhB;AACD;;AAEM,SAASG,mBAAT,CAA6BL,QAA7B,EAA0E;EAAA,IAA3BM,kBAA2B,uEAAN,IAAM;EAC/E,MAAMC,SAAS,GAAG,IAAAH,uBAAA,EAAiBJ,QAAjB,CAAlB;EACA,OAAOZ,OAAO,CAACmB,SAAS,CAACC,KAAV,CAAgB,eAAhB,KAAoCF,kBAArC,CAAd;AACD"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { AppState } from 'react-native';
|
|
3
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
4
|
+
const edgePaddingMap = {
|
|
5
|
+
left: 'paddingLeft',
|
|
6
|
+
right: 'paddingRight',
|
|
7
|
+
top: 'paddingTop',
|
|
8
|
+
bottom: 'paddingBottom'
|
|
9
|
+
};
|
|
10
|
+
export const useSafeAreaPadding = edges => {
|
|
11
|
+
const safeAreaInsets = useSafeAreaInsets();
|
|
12
|
+
return useMemo(() => {
|
|
13
|
+
return edges.reduce((map, edge) => {
|
|
14
|
+
const paddingKey = edgePaddingMap[edge];
|
|
15
|
+
map[paddingKey] = safeAreaInsets[edge];
|
|
16
|
+
return map;
|
|
17
|
+
}, {});
|
|
18
|
+
}, edges);
|
|
19
|
+
};
|
|
20
|
+
export const useAppState = (type, listener) => {
|
|
21
|
+
const callbackRef = useRef(listener);
|
|
22
|
+
callbackRef.current = listener;
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const eventListener = state => callbackRef.current(state);
|
|
25
|
+
|
|
26
|
+
const subscriber = AppState.addEventListener(type, eventListener);
|
|
27
|
+
return () => {
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
if (subscriber !== null && subscriber !== void 0 && subscriber.remove) {
|
|
30
|
+
subscriber.remove();
|
|
31
|
+
} // @ts-ignore
|
|
32
|
+
else if (AppState.removeEventListener) {
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
AppState.removeEventListener(type, eventListener);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}, []);
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=react-native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","useMemo","useRef","AppState","useSafeAreaInsets","edgePaddingMap","left","right","top","bottom","useSafeAreaPadding","edges","safeAreaInsets","reduce","map","edge","paddingKey","useAppState","type","listener","callbackRef","current","eventListener","state","subscriber","addEventListener","remove","removeEventListener"],"sources":["react-native.ts"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\nimport { AppState, AppStateEvent, AppStateStatus } from 'react-native';\nimport { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';\n\ntype EdgePaddingMap = {\n left: 'paddingLeft';\n right: 'paddingRight';\n top: 'paddingTop';\n bottom: 'paddingBottom';\n};\nconst edgePaddingMap: EdgePaddingMap = {\n left: 'paddingLeft',\n right: 'paddingRight',\n top: 'paddingTop',\n bottom: 'paddingBottom',\n};\n\nexport const useSafeAreaPadding = <\n T extends keyof EdgeInsets,\n Result extends { [key in EdgePaddingMap[T]]: EdgeInsets[T] },\n>(\n edges: T[],\n): Result => {\n const safeAreaInsets = useSafeAreaInsets();\n return useMemo(() => {\n return edges.reduce((map, edge) => {\n const paddingKey = edgePaddingMap[edge];\n map[paddingKey] = safeAreaInsets[edge];\n return map;\n }, {} as { [key in EdgePaddingMap[T]]: EdgeInsets[T] });\n }, edges) as Result;\n};\n\ntype AppStateListener = (status: AppStateStatus) => void;\n\nexport const useAppState = (type: AppStateEvent, listener: AppStateListener) => {\n const callbackRef = useRef<AppStateListener>(listener);\n callbackRef.current = listener;\n\n useEffect(() => {\n const eventListener = (state: AppStateStatus) => callbackRef.current(state);\n const subscriber = AppState.addEventListener(type, eventListener);\n\n return () => {\n // @ts-ignore\n if (subscriber?.remove) {\n subscriber.remove();\n }\n // @ts-ignore\n else if (AppState.removeEventListener) {\n // @ts-ignore\n AppState.removeEventListener(type, eventListener);\n }\n };\n }, []);\n};\n"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,OAApB,EAA6BC,MAA7B,QAA2C,OAA3C;AACA,SAASC,QAAT,QAAwD,cAAxD;AACA,SAAqBC,iBAArB,QAA8C,gCAA9C;AAQA,MAAMC,cAA8B,GAAG;EACrCC,IAAI,EAAE,aAD+B;EAErCC,KAAK,EAAE,cAF8B;EAGrCC,GAAG,EAAE,YAHgC;EAIrCC,MAAM,EAAE;AAJ6B,CAAvC;AAOA,OAAO,MAAMC,kBAAkB,GAI7BC,KAJgC,IAKrB;EACX,MAAMC,cAAc,GAAGR,iBAAiB,EAAxC;EACA,OAAOH,OAAO,CAAC,MAAM;IACnB,OAAOU,KAAK,CAACE,MAAN,CAAa,CAACC,GAAD,EAAMC,IAAN,KAAe;MACjC,MAAMC,UAAU,GAAGX,cAAc,CAACU,IAAD,CAAjC;MACAD,GAAG,CAACE,UAAD,CAAH,GAAkBJ,cAAc,CAACG,IAAD,CAAhC;MACA,OAAOD,GAAP;IACD,CAJM,EAIJ,EAJI,CAAP;EAKD,CANa,EAMXH,KANW,CAAd;AAOD,CAdM;AAkBP,OAAO,MAAMM,WAAW,GAAG,CAACC,IAAD,EAAsBC,QAAtB,KAAqD;EAC9E,MAAMC,WAAW,GAAGlB,MAAM,CAAmBiB,QAAnB,CAA1B;EACAC,WAAW,CAACC,OAAZ,GAAsBF,QAAtB;EAEAnB,SAAS,CAAC,MAAM;IACd,MAAMsB,aAAa,GAAIC,KAAD,IAA2BH,WAAW,CAACC,OAAZ,CAAoBE,KAApB,CAAjD;;IACA,MAAMC,UAAU,GAAGrB,QAAQ,CAACsB,gBAAT,CAA0BP,IAA1B,EAAgCI,aAAhC,CAAnB;IAEA,OAAO,MAAM;MACX;MACA,IAAIE,UAAJ,aAAIA,UAAJ,eAAIA,UAAU,CAAEE,MAAhB,EAAwB;QACtBF,UAAU,CAACE,MAAX;MACD,CAFD,CAGA;MAHA,KAIK,IAAIvB,QAAQ,CAACwB,mBAAb,EAAkC;QACrC;QACAxB,QAAQ,CAACwB,mBAAT,CAA6BT,IAA7B,EAAmCI,aAAnC;MACD;IACF,CAVD;EAWD,CAfQ,EAeN,EAfM,CAAT;AAgBD,CApBM"}
|
package/lib/module/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { Logger } from './shared/logger';
|
|
2
2
|
export { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';
|
|
3
3
|
export { createPubSub } from './shared/pubsub';
|
|
4
|
-
export { default as conditionChaining } from './shared/conditionChaining';
|
|
5
4
|
export { urlRegexStrict, urlRegexRough, newLineRegex, audioExtRegex, videoExtRegex, imageExtRegex, getFileType, getFileExtension, replaceUrlAsComponents, normalizeFileName, emailRegex, phoneRegex, replaceWithRegex, createMentionTemplateRegex } from './shared/regex';
|
|
6
5
|
export { BufferedRequest } from './shared/bufferedRequest';
|
|
7
|
-
export
|
|
6
|
+
export * from './shared';
|
|
8
7
|
export * from './hooks';
|
|
8
|
+
export * from './hooks/react-native';
|
|
9
9
|
export * from './ui-format/groupChannel';
|
|
10
10
|
export * from './ui-format/common';
|
|
11
11
|
export * from './sendbird/channel';
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Logger","default","arrayToMap","arrayToMapWithGetter","createPubSub","
|
|
1
|
+
{"version":3,"names":["Logger","default","arrayToMap","arrayToMapWithGetter","createPubSub","urlRegexStrict","urlRegexRough","newLineRegex","audioExtRegex","videoExtRegex","imageExtRegex","getFileType","getFileExtension","replaceUrlAsComponents","normalizeFileName","emailRegex","phoneRegex","replaceWithRegex","createMentionTemplateRegex","BufferedRequest","NOOP","ASYNC_NOOP","PASS","val","toMegabyte","byte","isFunction","param","SBErrorCode","NON_AUTHORIZED","SBErrorMessage","ACL"],"sources":["index.ts"],"sourcesContent":["export { Logger } from './shared/logger';\nexport { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';\nexport { createPubSub } from './shared/pubsub';\nexport {\n urlRegexStrict,\n urlRegexRough,\n newLineRegex,\n audioExtRegex,\n videoExtRegex,\n imageExtRegex,\n getFileType,\n getFileExtension,\n replaceUrlAsComponents,\n normalizeFileName,\n emailRegex,\n phoneRegex,\n replaceWithRegex,\n createMentionTemplateRegex,\n} from './shared/regex';\nexport { BufferedRequest } from './shared/bufferedRequest';\n\nexport * from './shared';\n\nexport * from './hooks';\nexport * from './hooks/react-native';\nexport * from './ui-format/groupChannel';\nexport * from './ui-format/common';\nexport * from './sendbird/channel';\nexport * from './sendbird/message';\nexport * from './sendbird/attrs';\nexport * from './sendbird/user';\n\nexport const NOOP: () => void = () => void 0;\nexport const ASYNC_NOOP = async () => void 0;\nexport const PASS = <T>(val: T) => val;\nexport const toMegabyte = (byte: number) => byte / 1024 / 1024;\nexport const isFunction = <T>(param?: T): param is NonNullable<T> => typeof param === 'function';\nexport const SBErrorCode = {\n NON_AUTHORIZED: 400108,\n};\nexport const SBErrorMessage = {\n ACL:\n 'Sendbird provides various access control options when using the Chat SDK.\\n' +\n 'By default, the Allow retrieving user list attribute is turned on to facilitate creating sample apps.\\n' +\n 'However, this may grant access to unwanted data or operations, leading to potential security concerns.\\n' +\n 'To manage your access control settings, you can turn on or off each setting on Sendbird Dashboard.',\n};\n\nexport type {\n UserStruct,\n FilterByValueType,\n UnionToIntersection,\n OmittedValues,\n PartialDeep,\n Optional,\n ContextValue,\n SendbirdMessage,\n SendbirdChatSDK,\n SendbirdChannel,\n SendbirdBaseChannel,\n SendbirdGroupChannel,\n SendbirdOpenChannel,\n SendbirdUser,\n SendbirdMember,\n SendbirdBaseMessage,\n SendbirdUserMessage,\n SendbirdFileMessage,\n SendbirdAdminMessage,\n SendbirdGroupChannelCreateParams,\n SendbirdFileMessageCreateParams,\n SendbirdUserMessageCreateParams,\n SendbirdError,\n SendbirdMessageCollection,\n SendbirdGroupChannelCollection,\n NotificationFiles,\n NotificationMentionedUsers,\n NotificationTranslations,\n PartialNullable,\n SendbirdDataPayload,\n SendbirdPreviousMessageListQuery,\n SendbirdSendableMessage,\n SendbirdGroupChannelListQuery,\n SendbirdGroupChannelUpdateParams,\n SendbirdUserMessageUpdateParams,\n SendbirdFileMessageUpdateParams,\n SendbirdUserUpdateParams,\n SendbirdRestrictedUser,\n SendbirdReaction,\n SendbirdEmojiContainer,\n SendbirdEmoji,\n SendbirdEmojiCategory,\n} from './types';\n"],"mappings":"AAAA,SAASA,MAAT,QAAuB,iBAAvB;AACA,SAASC,OAAO,IAAIC,UAApB,EAAgCC,oBAAhC,QAA4D,qBAA5D;AACA,SAASC,YAAT,QAA6B,iBAA7B;AACA,SACEC,cADF,EAEEC,aAFF,EAGEC,YAHF,EAIEC,aAJF,EAKEC,aALF,EAMEC,aANF,EAOEC,WAPF,EAQEC,gBARF,EASEC,sBATF,EAUEC,iBAVF,EAWEC,UAXF,EAYEC,UAZF,EAaEC,gBAbF,EAcEC,0BAdF,QAeO,gBAfP;AAgBA,SAASC,eAAT,QAAgC,0BAAhC;AAEA,cAAc,UAAd;AAEA,cAAc,SAAd;AACA,cAAc,sBAAd;AACA,cAAc,0BAAd;AACA,cAAc,oBAAd;AACA,cAAc,oBAAd;AACA,cAAc,oBAAd;AACA,cAAc,kBAAd;AACA,cAAc,iBAAd;AAEA,OAAO,MAAMC,IAAgB,GAAG,MAAM,KAAK,CAApC;AACP,OAAO,MAAMC,UAAU,GAAG,YAAY,KAAK,CAApC;AACP,OAAO,MAAMC,IAAI,GAAOC,GAAJ,IAAeA,GAA5B;AACP,OAAO,MAAMC,UAAU,GAAIC,IAAD,IAAkBA,IAAI,GAAG,IAAP,GAAc,IAAnD;AACP,OAAO,MAAMC,UAAU,GAAOC,KAAJ,IAA2C,OAAOA,KAAP,KAAiB,UAA/E;AACP,OAAO,MAAMC,WAAW,GAAG;EACzBC,cAAc,EAAE;AADS,CAApB;AAGP,OAAO,MAAMC,cAAc,GAAG;EAC5BC,GAAG,EACD,gFACA,yGADA,GAEA,0GAFA,GAGA;AAL0B,CAAvB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { getFileExtension, getFileType } from './regex';
|
|
2
|
+
/**
|
|
3
|
+
* Converts a given string to a hashed string.
|
|
4
|
+
* */
|
|
5
|
+
|
|
6
|
+
export function hash(str) {
|
|
7
|
+
return String(Math.abs(str.split('').reduce((a, c) => (a << 5) - a + c.charCodeAt(0) | 0, 0)));
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Replace a specific range of text in the string with another text.
|
|
11
|
+
* */
|
|
12
|
+
|
|
13
|
+
export function replace(str, start, end, text) {
|
|
14
|
+
return str.slice(0, start) + text + str.slice(end);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns the value corresponding to the first true index of a given condition array.
|
|
18
|
+
* */
|
|
19
|
+
|
|
20
|
+
export function conditionChaining(conditions, values) {
|
|
21
|
+
const idx = conditions.findIndex(state => Boolean(state));
|
|
22
|
+
return idx > -1 ? values[idx] : values[values.length - 1];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Calculates the downscale size.
|
|
26
|
+
* */
|
|
27
|
+
|
|
28
|
+
export function getDownscaleSize(origin, resizing) {
|
|
29
|
+
let ratio;
|
|
30
|
+
const maxWidth = resizing.width || origin.width,
|
|
31
|
+
maxHeight = resizing.height || origin.height;
|
|
32
|
+
|
|
33
|
+
if (origin.width <= maxWidth && origin.height <= maxHeight) {
|
|
34
|
+
ratio = 1;
|
|
35
|
+
} else if (origin.width > maxWidth && origin.height <= maxHeight) {
|
|
36
|
+
ratio = maxWidth / origin.width;
|
|
37
|
+
} else if (origin.width <= maxWidth && origin.height > maxHeight) {
|
|
38
|
+
ratio = maxHeight / origin.height;
|
|
39
|
+
} else {
|
|
40
|
+
ratio = Math.max(maxWidth / origin.width, maxHeight / origin.height);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
width: origin.width * ratio,
|
|
45
|
+
height: origin.height * ratio
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function isImage(filePath, mimeType) {
|
|
49
|
+
const type = getFileType(mimeType || getFileExtension(filePath));
|
|
50
|
+
return type === 'image';
|
|
51
|
+
}
|
|
52
|
+
export function shouldCompressImage(filePath) {
|
|
53
|
+
let compressionEnabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
54
|
+
const extension = getFileExtension(filePath);
|
|
55
|
+
return Boolean(extension.match(/jpg|jpeg|png/i) && compressionEnabled);
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getFileExtension","getFileType","hash","str","String","Math","abs","split","reduce","a","c","charCodeAt","replace","start","end","text","slice","conditionChaining","conditions","values","idx","findIndex","state","Boolean","length","getDownscaleSize","origin","resizing","ratio","maxWidth","width","maxHeight","height","max","isImage","filePath","mimeType","type","shouldCompressImage","compressionEnabled","extension","match"],"sources":["index.ts"],"sourcesContent":["import { getFileExtension, getFileType } from './regex';\n\n/**\n * Converts a given string to a hashed string.\n * */\nexport function hash(str: string) {\n return String(Math.abs(str.split('').reduce((a, c) => ((a << 5) - a + c.charCodeAt(0)) | 0, 0)));\n}\n\n/**\n * Replace a specific range of text in the string with another text.\n * */\nexport function replace(str: string, start: number, end: number, text: string) {\n return str.slice(0, start) + text + str.slice(end);\n}\n\n/**\n * Returns the value corresponding to the first true index of a given condition array.\n * */\nexport function conditionChaining<T, V>(conditions: T[], values: V[]) {\n const idx = conditions.findIndex((state) => Boolean(state));\n return idx > -1 ? values[idx] : values[values.length - 1];\n}\n\n/**\n * Calculates the downscale size.\n * */\ntype Size = { width: number; height: number };\nexport function getDownscaleSize(origin: Size, resizing: Partial<Size>) {\n let ratio;\n\n const maxWidth = resizing.width || origin.width,\n maxHeight = resizing.height || origin.height;\n\n if (origin.width <= maxWidth && origin.height <= maxHeight) {\n ratio = 1;\n } else if (origin.width > maxWidth && origin.height <= maxHeight) {\n ratio = maxWidth / origin.width;\n } else if (origin.width <= maxWidth && origin.height > maxHeight) {\n ratio = maxHeight / origin.height;\n } else {\n ratio = Math.max(maxWidth / origin.width, maxHeight / origin.height);\n }\n\n return { width: origin.width * ratio, height: origin.height * ratio };\n}\n\nexport function isImage(filePath: string, mimeType?: string) {\n const type = getFileType(mimeType || getFileExtension(filePath));\n return type === 'image';\n}\n\nexport function shouldCompressImage(filePath: string, compressionEnabled = true) {\n const extension = getFileExtension(filePath);\n return Boolean(extension.match(/jpg|jpeg|png/i) && compressionEnabled);\n}\n"],"mappings":"AAAA,SAASA,gBAAT,EAA2BC,WAA3B,QAA8C,SAA9C;AAEA;AACA;AACA;;AACA,OAAO,SAASC,IAAT,CAAcC,GAAd,EAA2B;EAChC,OAAOC,MAAM,CAACC,IAAI,CAACC,GAAL,CAASH,GAAG,CAACI,KAAJ,CAAU,EAAV,EAAcC,MAAd,CAAqB,CAACC,CAAD,EAAIC,CAAJ,KAAW,CAACD,CAAC,IAAI,CAAN,IAAWA,CAAX,GAAeC,CAAC,CAACC,UAAF,CAAa,CAAb,CAAhB,GAAmC,CAAlE,EAAqE,CAArE,CAAT,CAAD,CAAb;AACD;AAED;AACA;AACA;;AACA,OAAO,SAASC,OAAT,CAAiBT,GAAjB,EAA8BU,KAA9B,EAA6CC,GAA7C,EAA0DC,IAA1D,EAAwE;EAC7E,OAAOZ,GAAG,CAACa,KAAJ,CAAU,CAAV,EAAaH,KAAb,IAAsBE,IAAtB,GAA6BZ,GAAG,CAACa,KAAJ,CAAUF,GAAV,CAApC;AACD;AAED;AACA;AACA;;AACA,OAAO,SAASG,iBAAT,CAAiCC,UAAjC,EAAkDC,MAAlD,EAA+D;EACpE,MAAMC,GAAG,GAAGF,UAAU,CAACG,SAAX,CAAsBC,KAAD,IAAWC,OAAO,CAACD,KAAD,CAAvC,CAAZ;EACA,OAAOF,GAAG,GAAG,CAAC,CAAP,GAAWD,MAAM,CAACC,GAAD,CAAjB,GAAyBD,MAAM,CAACA,MAAM,CAACK,MAAP,GAAgB,CAAjB,CAAtC;AACD;AAED;AACA;AACA;;AAEA,OAAO,SAASC,gBAAT,CAA0BC,MAA1B,EAAwCC,QAAxC,EAAiE;EACtE,IAAIC,KAAJ;EAEA,MAAMC,QAAQ,GAAGF,QAAQ,CAACG,KAAT,IAAkBJ,MAAM,CAACI,KAA1C;EAAA,MACEC,SAAS,GAAGJ,QAAQ,CAACK,MAAT,IAAmBN,MAAM,CAACM,MADxC;;EAGA,IAAIN,MAAM,CAACI,KAAP,IAAgBD,QAAhB,IAA4BH,MAAM,CAACM,MAAP,IAAiBD,SAAjD,EAA4D;IAC1DH,KAAK,GAAG,CAAR;EACD,CAFD,MAEO,IAAIF,MAAM,CAACI,KAAP,GAAeD,QAAf,IAA2BH,MAAM,CAACM,MAAP,IAAiBD,SAAhD,EAA2D;IAChEH,KAAK,GAAGC,QAAQ,GAAGH,MAAM,CAACI,KAA1B;EACD,CAFM,MAEA,IAAIJ,MAAM,CAACI,KAAP,IAAgBD,QAAhB,IAA4BH,MAAM,CAACM,MAAP,GAAgBD,SAAhD,EAA2D;IAChEH,KAAK,GAAGG,SAAS,GAAGL,MAAM,CAACM,MAA3B;EACD,CAFM,MAEA;IACLJ,KAAK,GAAGvB,IAAI,CAAC4B,GAAL,CAASJ,QAAQ,GAAGH,MAAM,CAACI,KAA3B,EAAkCC,SAAS,GAAGL,MAAM,CAACM,MAArD,CAAR;EACD;;EAED,OAAO;IAAEF,KAAK,EAAEJ,MAAM,CAACI,KAAP,GAAeF,KAAxB;IAA+BI,MAAM,EAAEN,MAAM,CAACM,MAAP,GAAgBJ;EAAvD,CAAP;AACD;AAED,OAAO,SAASM,OAAT,CAAiBC,QAAjB,EAAmCC,QAAnC,EAAsD;EAC3D,MAAMC,IAAI,GAAGpC,WAAW,CAACmC,QAAQ,IAAIpC,gBAAgB,CAACmC,QAAD,CAA7B,CAAxB;EACA,OAAOE,IAAI,KAAK,OAAhB;AACD;AAED,OAAO,SAASC,mBAAT,CAA6BH,QAA7B,EAA0E;EAAA,IAA3BI,kBAA2B,uEAAN,IAAM;EAC/E,MAAMC,SAAS,GAAGxC,gBAAgB,CAACmC,QAAD,CAAlC;EACA,OAAOZ,OAAO,CAACiB,SAAS,CAACC,KAAV,CAAgB,eAAhB,KAAoCF,kBAArC,CAAd;AACD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AppStateEvent, AppStateStatus } from 'react-native';
|
|
2
|
+
import { EdgeInsets } from 'react-native-safe-area-context';
|
|
3
|
+
type EdgePaddingMap = {
|
|
4
|
+
left: 'paddingLeft';
|
|
5
|
+
right: 'paddingRight';
|
|
6
|
+
top: 'paddingTop';
|
|
7
|
+
bottom: 'paddingBottom';
|
|
8
|
+
};
|
|
9
|
+
export declare const useSafeAreaPadding: <T extends keyof EdgeInsets, Result extends { [key in EdgePaddingMap[T]]: EdgeInsets[T]; }>(edges: T[]) => Result;
|
|
10
|
+
type AppStateListener = (status: AppStateStatus) => void;
|
|
11
|
+
export declare const useAppState: (type: AppStateEvent, listener: AppStateListener) => void;
|
|
12
|
+
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { Logger } from './shared/logger';
|
|
2
2
|
export { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';
|
|
3
3
|
export { createPubSub } from './shared/pubsub';
|
|
4
|
-
export { default as conditionChaining } from './shared/conditionChaining';
|
|
5
4
|
export { urlRegexStrict, urlRegexRough, newLineRegex, audioExtRegex, videoExtRegex, imageExtRegex, getFileType, getFileExtension, replaceUrlAsComponents, normalizeFileName, emailRegex, phoneRegex, replaceWithRegex, createMentionTemplateRegex, } from './shared/regex';
|
|
6
5
|
export { BufferedRequest } from './shared/bufferedRequest';
|
|
7
|
-
export
|
|
6
|
+
export * from './shared';
|
|
8
7
|
export * from './hooks';
|
|
8
|
+
export * from './hooks/react-native';
|
|
9
9
|
export * from './ui-format/groupChannel';
|
|
10
10
|
export * from './ui-format/common';
|
|
11
11
|
export * from './sendbird/channel';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a given string to a hashed string.
|
|
3
|
+
* */
|
|
4
|
+
export declare function hash(str: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Replace a specific range of text in the string with another text.
|
|
7
|
+
* */
|
|
8
|
+
export declare function replace(str: string, start: number, end: number, text: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the value corresponding to the first true index of a given condition array.
|
|
11
|
+
* */
|
|
12
|
+
export declare function conditionChaining<T, V>(conditions: T[], values: V[]): V;
|
|
13
|
+
/**
|
|
14
|
+
* Calculates the downscale size.
|
|
15
|
+
* */
|
|
16
|
+
type Size = {
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
};
|
|
20
|
+
export declare function getDownscaleSize(origin: Size, resizing: Partial<Size>): {
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
};
|
|
24
|
+
export declare function isImage(filePath: string, mimeType?: string): boolean;
|
|
25
|
+
export declare function shouldCompressImage(filePath: string, compressionEnabled?: boolean): boolean;
|
|
26
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sendbird/uikit-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "UIKit utilities",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/react": "*",
|
|
46
|
+
"@types/react-native": "*",
|
|
46
47
|
"react": "17.0.2",
|
|
47
48
|
"react-native": "0.67.4",
|
|
48
49
|
"react-native-builder-bob": "^0.18.0",
|
|
@@ -76,5 +77,5 @@
|
|
|
76
77
|
"readmeFile": "./README.md",
|
|
77
78
|
"displayName": "@sendbird/uikit-utils"
|
|
78
79
|
},
|
|
79
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "a9bf41fd7919436db99f6cc3bacd0f8d791b7729"
|
|
80
81
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { AppState, AppStateEvent, AppStateStatus } from 'react-native';
|
|
3
|
+
import { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
4
|
+
|
|
5
|
+
type EdgePaddingMap = {
|
|
6
|
+
left: 'paddingLeft';
|
|
7
|
+
right: 'paddingRight';
|
|
8
|
+
top: 'paddingTop';
|
|
9
|
+
bottom: 'paddingBottom';
|
|
10
|
+
};
|
|
11
|
+
const edgePaddingMap: EdgePaddingMap = {
|
|
12
|
+
left: 'paddingLeft',
|
|
13
|
+
right: 'paddingRight',
|
|
14
|
+
top: 'paddingTop',
|
|
15
|
+
bottom: 'paddingBottom',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const useSafeAreaPadding = <
|
|
19
|
+
T extends keyof EdgeInsets,
|
|
20
|
+
Result extends { [key in EdgePaddingMap[T]]: EdgeInsets[T] },
|
|
21
|
+
>(
|
|
22
|
+
edges: T[],
|
|
23
|
+
): Result => {
|
|
24
|
+
const safeAreaInsets = useSafeAreaInsets();
|
|
25
|
+
return useMemo(() => {
|
|
26
|
+
return edges.reduce((map, edge) => {
|
|
27
|
+
const paddingKey = edgePaddingMap[edge];
|
|
28
|
+
map[paddingKey] = safeAreaInsets[edge];
|
|
29
|
+
return map;
|
|
30
|
+
}, {} as { [key in EdgePaddingMap[T]]: EdgeInsets[T] });
|
|
31
|
+
}, edges) as Result;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type AppStateListener = (status: AppStateStatus) => void;
|
|
35
|
+
|
|
36
|
+
export const useAppState = (type: AppStateEvent, listener: AppStateListener) => {
|
|
37
|
+
const callbackRef = useRef<AppStateListener>(listener);
|
|
38
|
+
callbackRef.current = listener;
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const eventListener = (state: AppStateStatus) => callbackRef.current(state);
|
|
42
|
+
const subscriber = AppState.addEventListener(type, eventListener);
|
|
43
|
+
|
|
44
|
+
return () => {
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
if (subscriber?.remove) {
|
|
47
|
+
subscriber.remove();
|
|
48
|
+
}
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
else if (AppState.removeEventListener) {
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
AppState.removeEventListener(type, eventListener);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}, []);
|
|
56
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { Logger } from './shared/logger';
|
|
2
2
|
export { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';
|
|
3
3
|
export { createPubSub } from './shared/pubsub';
|
|
4
|
-
export { default as conditionChaining } from './shared/conditionChaining';
|
|
5
4
|
export {
|
|
6
5
|
urlRegexStrict,
|
|
7
6
|
urlRegexRough,
|
|
@@ -19,9 +18,11 @@ export {
|
|
|
19
18
|
createMentionTemplateRegex,
|
|
20
19
|
} from './shared/regex';
|
|
21
20
|
export { BufferedRequest } from './shared/bufferedRequest';
|
|
22
|
-
|
|
21
|
+
|
|
22
|
+
export * from './shared';
|
|
23
23
|
|
|
24
24
|
export * from './hooks';
|
|
25
|
+
export * from './hooks/react-native';
|
|
25
26
|
export * from './ui-format/groupChannel';
|
|
26
27
|
export * from './ui-format/common';
|
|
27
28
|
export * from './sendbird/channel';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { getFileExtension, getFileType } from './regex';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts a given string to a hashed string.
|
|
5
|
+
* */
|
|
6
|
+
export function hash(str: string) {
|
|
7
|
+
return String(Math.abs(str.split('').reduce((a, c) => ((a << 5) - a + c.charCodeAt(0)) | 0, 0)));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Replace a specific range of text in the string with another text.
|
|
12
|
+
* */
|
|
13
|
+
export function replace(str: string, start: number, end: number, text: string) {
|
|
14
|
+
return str.slice(0, start) + text + str.slice(end);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns the value corresponding to the first true index of a given condition array.
|
|
19
|
+
* */
|
|
20
|
+
export function conditionChaining<T, V>(conditions: T[], values: V[]) {
|
|
21
|
+
const idx = conditions.findIndex((state) => Boolean(state));
|
|
22
|
+
return idx > -1 ? values[idx] : values[values.length - 1];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Calculates the downscale size.
|
|
27
|
+
* */
|
|
28
|
+
type Size = { width: number; height: number };
|
|
29
|
+
export function getDownscaleSize(origin: Size, resizing: Partial<Size>) {
|
|
30
|
+
let ratio;
|
|
31
|
+
|
|
32
|
+
const maxWidth = resizing.width || origin.width,
|
|
33
|
+
maxHeight = resizing.height || origin.height;
|
|
34
|
+
|
|
35
|
+
if (origin.width <= maxWidth && origin.height <= maxHeight) {
|
|
36
|
+
ratio = 1;
|
|
37
|
+
} else if (origin.width > maxWidth && origin.height <= maxHeight) {
|
|
38
|
+
ratio = maxWidth / origin.width;
|
|
39
|
+
} else if (origin.width <= maxWidth && origin.height > maxHeight) {
|
|
40
|
+
ratio = maxHeight / origin.height;
|
|
41
|
+
} else {
|
|
42
|
+
ratio = Math.max(maxWidth / origin.width, maxHeight / origin.height);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return { width: origin.width * ratio, height: origin.height * ratio };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function isImage(filePath: string, mimeType?: string) {
|
|
49
|
+
const type = getFileType(mimeType || getFileExtension(filePath));
|
|
50
|
+
return type === 'image';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function shouldCompressImage(filePath: string, compressionEnabled = true) {
|
|
54
|
+
const extension = getFileExtension(filePath);
|
|
55
|
+
return Boolean(extension.match(/jpg|jpeg|png/i) && compressionEnabled);
|
|
56
|
+
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
const conditionChaining = (conditions, values) => {
|
|
9
|
-
const idx = conditions.findIndex(state => Boolean(state));
|
|
10
|
-
return idx > -1 ? values[idx] : values[values.length - 1];
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
var _default = conditionChaining;
|
|
14
|
-
exports.default = _default;
|
|
15
|
-
//# sourceMappingURL=conditionChaining.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["conditionChaining","conditions","values","idx","findIndex","state","Boolean","length"],"sources":["conditionChaining.ts"],"sourcesContent":["const conditionChaining = <T, V>(conditions: T[], values: V[]) => {\n const idx = conditions.findIndex((state) => Boolean(state));\n return idx > -1 ? values[idx] : values[values.length - 1];\n};\n\nexport default conditionChaining;\n"],"mappings":";;;;;;;AAAA,MAAMA,iBAAiB,GAAG,CAAOC,UAAP,EAAwBC,MAAxB,KAAwC;EAChE,MAAMC,GAAG,GAAGF,UAAU,CAACG,SAAX,CAAsBC,KAAD,IAAWC,OAAO,CAACD,KAAD,CAAvC,CAAZ;EACA,OAAOF,GAAG,GAAG,CAAC,CAAP,GAAWD,MAAM,CAACC,GAAD,CAAjB,GAAyBD,MAAM,CAACA,MAAM,CAACK,MAAP,GAAgB,CAAjB,CAAtC;AACD,CAHD;;eAKeP,iB"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
const replace = (original, start, end, str) => {
|
|
9
|
-
return original.slice(0, start) + str + original.slice(end);
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
var _default = replace;
|
|
13
|
-
exports.default = _default;
|
|
14
|
-
//# sourceMappingURL=replace.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["replace","original","start","end","str","slice"],"sources":["replace.ts"],"sourcesContent":["const replace = (original: string, start: number, end: number, str: string) => {\n return original.slice(0, start) + str + original.slice(end);\n};\n\nexport default replace;\n"],"mappings":";;;;;;;AAAA,MAAMA,OAAO,GAAG,CAACC,QAAD,EAAmBC,KAAnB,EAAkCC,GAAlC,EAA+CC,GAA/C,KAA+D;EAC7E,OAAOH,QAAQ,CAACI,KAAT,CAAe,CAAf,EAAkBH,KAAlB,IAA2BE,GAA3B,GAAiCH,QAAQ,CAACI,KAAT,CAAeF,GAAf,CAAxC;AACD,CAFD;;eAIeH,O"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["conditionChaining","conditions","values","idx","findIndex","state","Boolean","length"],"sources":["conditionChaining.ts"],"sourcesContent":["const conditionChaining = <T, V>(conditions: T[], values: V[]) => {\n const idx = conditions.findIndex((state) => Boolean(state));\n return idx > -1 ? values[idx] : values[values.length - 1];\n};\n\nexport default conditionChaining;\n"],"mappings":"AAAA,MAAMA,iBAAiB,GAAG,CAAOC,UAAP,EAAwBC,MAAxB,KAAwC;EAChE,MAAMC,GAAG,GAAGF,UAAU,CAACG,SAAX,CAAsBC,KAAD,IAAWC,OAAO,CAACD,KAAD,CAAvC,CAAZ;EACA,OAAOF,GAAG,GAAG,CAAC,CAAP,GAAWD,MAAM,CAACC,GAAD,CAAjB,GAAyBD,MAAM,CAACA,MAAM,CAACK,MAAP,GAAgB,CAAjB,CAAtC;AACD,CAHD;;AAKA,eAAeP,iBAAf"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["replace","original","start","end","str","slice"],"sources":["replace.ts"],"sourcesContent":["const replace = (original: string, start: number, end: number, str: string) => {\n return original.slice(0, start) + str + original.slice(end);\n};\n\nexport default replace;\n"],"mappings":"AAAA,MAAMA,OAAO,GAAG,CAACC,QAAD,EAAmBC,KAAnB,EAAkCC,GAAlC,EAA+CC,GAA/C,KAA+D;EAC7E,OAAOH,QAAQ,CAACI,KAAT,CAAe,CAAf,EAAkBH,KAAlB,IAA2BE,GAA3B,GAAiCH,QAAQ,CAACI,KAAT,CAAeF,GAAf,CAAxC;AACD,CAFD;;AAIA,eAAeH,OAAf"}
|