@vroskus/library-helpers 1.0.3 → 1.0.4

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/dist/node.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './common';
2
- type $GenerateHash = (value: string) => string;
3
- export declare const generateHash: $GenerateHash;
2
+ export declare const generateHash: (value: string) => string;
package/dist/node.js CHANGED
@@ -20,6 +20,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.generateHash = void 0;
21
21
  const crypto_1 = __importDefault(require("crypto"));
22
22
  __exportStar(require("./common"), exports);
23
- const generateHash = (v) => crypto_1.default.createHash('md5').update(v).digest('hex');
23
+ const generateHash = (value) => crypto_1.default.createHash('md5').update(value).digest('hex');
24
24
  exports.generateHash = generateHash;
25
25
  //# sourceMappingURL=node.js.map
package/dist/node.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AACA,oDAA4B;AAE5B,2CAAyB;AAIlB,MAAM,YAAY,GAAkB,CAAC,CAAC,EAAE,EAAE,CAAC,gBAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAAtF,QAAA,YAAY,gBAA0E"}
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AACA,oDAA4B;AAE5B,2CAAyB;AAElB,MAAM,YAAY,GAAG,CAC1B,KAAa,EACL,EAAE,CAAC,gBAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAFrD,QAAA,YAAY,gBAEyC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vroskus/library-helpers",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Utility helpers",
5
5
  "author": "Vilius Roškus <info@regattas.eu>",
6
6
  "license": "MIT",
@@ -9,6 +9,9 @@
9
9
  "url": "git+https://github.com/vroskus/library-helpers.git"
10
10
  },
11
11
  "main": "dist/index.js",
12
+ "files": [
13
+ "dist/"
14
+ ],
12
15
  "scripts": {
13
16
  "postinstall": "npm run build",
14
17
  "build": "tsc",
@@ -17,6 +20,7 @@
17
20
  "test:e2e": "echo 'No tests'"
18
21
  },
19
22
  "dependencies": {
23
+ "@types/express": "4.17.17",
20
24
  "aigle": "1.14.1",
21
25
  "aphrodite": "2.4.0",
22
26
  "express": "4.18.2",
@@ -26,7 +30,6 @@
26
30
  "short-hash": "1.0.0"
27
31
  },
28
32
  "devDependencies": {
29
- "@types/express": "4.17.17",
30
33
  "@types/jest": "29.5.0",
31
34
  "@types/lodash": "4.14.192",
32
35
  "@types/node": "18.15.11",
package/.eslintrc DELETED
@@ -1,77 +0,0 @@
1
- {
2
- "root": true,
3
- "parser": "@typescript-eslint/parser",
4
- "parserOptions": {
5
- "requireConfigFile": false,
6
- "project": ["tsconfig.json"]
7
- },
8
- "extends": [
9
- "airbnb-base",
10
- "airbnb-typescript",
11
- "plugin:import/recommended",
12
- "plugin:@typescript-eslint/eslint-recommended",
13
- "plugin:@typescript-eslint/recommended",
14
- "plugin:sort/recommended"
15
- ],
16
- "plugins": [
17
- "@typescript-eslint",
18
- "import",
19
- "import-newlines",
20
- "react",
21
- "sort"
22
- ],
23
- "rules": {
24
- "complexity": ["error", 5],
25
- "@typescript-eslint/ban-ts-comment": [1],
26
- "@typescript-eslint/no-unused-vars": [2],
27
- "curly": ["error", "all"],
28
- "import/no-cycle": [0],
29
- "no-await-in-loop": 0,
30
- "no-console": "error",
31
- "no-duplicate-imports": [0],
32
- "no-loss-of-precision": [0],
33
- "no-restricted-syntax": 0,
34
- "no-unreachable-loop": [0],
35
- "no-useless-backreference": [0],
36
- "no-unused-private-class-members": [2],
37
- "padding-line-between-statements": ["error", {
38
- "blankLine": "always",
39
- "prev": ["const", "let"],
40
- "next": "*"
41
- }, {
42
- "blankLine": "any",
43
- "prev": ["const", "let"],
44
- "next": ["const", "let"]
45
- }, {
46
- "blankLine": "always",
47
- "prev": ["if", "function", "for"],
48
- "next": "*"
49
- }, {
50
- "blankLine": "always",
51
- "prev": "*",
52
- "next": "return"
53
- }],
54
- "object-curly-newline": ["error", {
55
- "ObjectExpression": "always",
56
- "ObjectPattern": "always",
57
- "ImportDeclaration": "always",
58
- "ExportDeclaration": "always"
59
- }],
60
- "function-call-argument-newline": ["error", "always"],
61
- "object-property-newline": ["error", {
62
- "allowMultiplePropertiesPerLine": false
63
- }],
64
- "import-newlines/enforce": ["error", {
65
- "items": 1,
66
- "forceSingleLine": false
67
- }],
68
- "sort/imports": [0],
69
- "sort/exports": [0]
70
- },
71
- "env": {
72
- "browser": true,
73
- "node": true,
74
- "jest": true,
75
- "es6": true
76
- }
77
- }
package/src/browser.ts DELETED
@@ -1,121 +0,0 @@
1
- // Helpers
2
- import _ from 'lodash';
3
- import qs from 'query-string';
4
- import {
5
- fadeIn,
6
- fadeInDown,
7
- fadeInUp,
8
- } from 'react-animations';
9
- import {
10
- css,
11
- StyleSheet,
12
- } from 'aphrodite';
13
-
14
- export * from './common';
15
-
16
- const isEmptyString = (value: unknown): boolean => {
17
- if (typeof value === 'string' && value.trim().length === 0) {
18
- return true;
19
- }
20
-
21
- return false;
22
- };
23
-
24
- export const cleanFormValues = <D extends Record<string, unknown>>(
25
- data: Record<string, unknown>,
26
- ): D => {
27
- const withoutHiddenItemsData = _.omitBy(
28
- data,
29
- (value, key: string) => _.startsWith(
30
- key,
31
- '_',
32
- ),
33
- );
34
- const cleanData = _.mapValues(
35
- withoutHiddenItemsData,
36
- (value) => (value === '' || isEmptyString(value) ? null : value),
37
- ) as D;
38
-
39
- return cleanData;
40
- };
41
-
42
- export const numberValue = (input: '' | number): number => (input === '' ? 0 : input);
43
-
44
- type $AnimationName = 'fadeIn' | 'fadeInUp' | 'fadeInDown';
45
-
46
- export const animationClass = (name: $AnimationName): string => {
47
- const animations: Record<$AnimationName, unknown> = {
48
- fadeIn,
49
- fadeInDown,
50
- fadeInUp,
51
- };
52
-
53
- const style = StyleSheet.create({
54
- animation: {
55
- animationDuration: '1s',
56
- animationName: animations[name],
57
- },
58
- });
59
-
60
- return css(style.animation);
61
- };
62
-
63
- export const getUrlGetParams = (input: string): Record<string, string> => {
64
- const parsedData = qs.parse(input);
65
-
66
- const output = {
67
- };
68
-
69
- _.forEach(
70
- parsedData,
71
- (value: string | Array<string>, key: string) => {
72
- if (Array.isArray(value)) {
73
- output[key] = value.join(';');
74
- } else {
75
- output[key] = value;
76
- }
77
- },
78
- );
79
-
80
- return output;
81
- };
82
-
83
- const getScrollTopValue = (elementId?: string, offset?: number): number => {
84
- let value = 0;
85
-
86
- if (document && elementId) {
87
- const element = document.getElementById(elementId);
88
-
89
- if (element) {
90
- value = element.offsetTop - (offset || 15);
91
- }
92
- }
93
-
94
- return value;
95
- };
96
-
97
- export const scrollTop = (elementId?: string, offset?: number): void => {
98
- if (window && window.scrollTo) {
99
- window.scrollTo({
100
- behavior: 'smooth',
101
- top: getScrollTopValue(
102
- elementId,
103
- offset,
104
- ),
105
- });
106
- }
107
- };
108
-
109
- export const scrollItem = (itemId: string, elementId: string, offset?: number): void => {
110
- if (document) {
111
- const item = document.getElementById(itemId);
112
- const element = document.getElementById(elementId);
113
-
114
- if (item && element) {
115
- item.scroll({
116
- behavior: 'smooth',
117
- top: element.offsetTop + (offset || -50),
118
- });
119
- }
120
- }
121
- };
package/src/common.ts DELETED
@@ -1,116 +0,0 @@
1
- // Global Types
2
- import type {
3
- NextFunction as $Next,
4
- Request as $Request,
5
- Response as $Response,
6
- } from 'express';
7
-
8
- // Helpers
9
- import _ from 'lodash';
10
- import aigle from 'aigle';
11
- import sh from 'short-hash';
12
-
13
- const asyncLodash: _.LoDashStatic = aigle.mixin(
14
- _,
15
- undefined,
16
- );
17
-
18
- export const getValue = <V extends string | null | void>(value: V, defaultValue: V): V => {
19
- let output = defaultValue;
20
-
21
- if (value !== null && value !== '') {
22
- output = value;
23
- }
24
-
25
- return output;
26
- };
27
-
28
- export const durationMiddleware = <REQ extends ($Request & {
29
- start?: [number, number];
30
- }), RES extends $Response>() => (
31
- req: REQ & {
32
- start?: [number, number];
33
- },
34
- res: RES,
35
- next: $Next,
36
- ) => {
37
- const start: [number, number] = process.hrtime();
38
-
39
- req.start = start;
40
-
41
- next();
42
- };
43
-
44
- export const getDuration = (start: [number, number] | void): number => {
45
- let timeInMs = 0;
46
-
47
- if (start) {
48
- const end = process.hrtime(start);
49
-
50
- timeInMs = (end[0] * 1000000000 + end[1]) / 1000000;
51
- }
52
-
53
- return timeInMs;
54
- };
55
-
56
- export const sortData = async <D extends Array<Record<string, unknown>>>(
57
- data: D,
58
- field: string | Array<string>,
59
- reverse?: boolean,
60
- ): Promise<D> => asyncLodash
61
- .chain(data)
62
- .sortBy(field)
63
- .tap(reverse ? _.reverse : _.noop)
64
- .value() as D;
65
-
66
- export const getImageUrl = ({
67
- cdnUrl,
68
- image,
69
- size,
70
- undefinedImage,
71
- }: {
72
- cdnUrl: string;
73
- image?: string | null;
74
- size: 'min' | 'mid' | 'max' | 'sqr';
75
- undefinedImage?: string;
76
- }): string => {
77
- if (image) {
78
- return `${cdnUrl}/images/${size}/${image}`;
79
- }
80
-
81
- return `${cdnUrl}/static/${undefinedImage || 'dummy.png'}`;
82
- };
83
-
84
- export const getFileUrl = ({
85
- cdnUrl,
86
- file,
87
- }: {
88
- cdnUrl: string;
89
- file: string;
90
- }): string => `${cdnUrl}/files/${file}`;
91
-
92
- export const makeCode = (input: string): string => sh(input).toUpperCase();
93
-
94
- export const sleep = (milliseconds: number): Promise<void> => new Promise((resolve) => {
95
- setTimeout(
96
- resolve,
97
- milliseconds,
98
- );
99
- });
100
-
101
- export const isDiff = (param1: unknown, param2: unknown): boolean => _.isEqual(
102
- param1,
103
- param2,
104
- ) === false;
105
-
106
- export const getObjectKeys: <T extends Record<string, unknown>, K extends keyof T>(
107
- o: T,
108
- ) => K[] = Object.keys;
109
-
110
- export const getObjectValues: <T extends Record<string, unknown>, K extends keyof T>(
111
- o: T,
112
- ) => T[K][] = Object.values;
113
-
114
- export const getObjectEntries: <T extends Record<string, unknown>, K extends keyof T>(
115
- o: T,
116
- ) => [K, T[K]][] = Object.entries;
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- // eslint-disable-next-line no-console
2
- console.log('Please use platform dedicated library: /browser or /node');
package/src/node.ts DELETED
@@ -1,8 +0,0 @@
1
- // Helpers
2
- import crypto from 'crypto';
3
-
4
- export * from './common';
5
-
6
- type $GenerateHash = (value: string) => string;
7
-
8
- export const generateHash: $GenerateHash = (v) => crypto.createHash('md5').update(v).digest('hex');
package/tsconfig.json DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "./dist/",
4
- "module": "commonjs",
5
- "esModuleInterop": true,
6
- "declaration": true,
7
- "noImplicitAny": false,
8
- "removeComments": true,
9
- "noLib": false,
10
- "emitDecoratorMetadata": true,
11
- "experimentalDecorators": true,
12
- "target": "es6",
13
- "sourceMap": true,
14
- "lib": [
15
- "dom",
16
- "es6"
17
- ]
18
- },
19
- "exclude": [
20
- "node_modules",
21
- "./dist/**/*"
22
- ],
23
- "include": [
24
- "./src"
25
- ]
26
- }