mielk-fn 1.0.0 → 1.0.2

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 CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "mielk-fn",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Set of helpful functions",
5
- "main": "index.js",
5
+ "main": "lib/index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1"
8
+ "prepublish": "npm test",
9
+ "test": "jest",
10
+ "build": "tsc"
9
11
  },
10
12
  "repository": {
11
13
  "type": "git",
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ import arrays from './methods/arrays';
2
+ import objects from './methods/objects';
3
+
4
+ export { arrays, objects };
@@ -1,5 +1,3 @@
1
- import { isDate } from 'util/types';
2
-
3
1
  type AnyObject = { [key: string]: any };
4
2
  type NumberStringFunction = (key: string, item: any) => number | string;
5
3
 
@@ -1,4 +1,4 @@
1
- import arrays from '../src/arrays';
1
+ import arrays from '../src/methods/arrays';
2
2
 
3
3
  /**
4
4
  * Unit tests for toMap function
@@ -1,4 +1,4 @@
1
- import objects from '../src/objects';
1
+ import objects from '../src/methods/objects';
2
2
 
3
3
  describe('isObject', () => {
4
4
  const isObject = objects.isObject;
@@ -50,7 +50,7 @@ describe('isObject', () => {
50
50
  describe('isPlainObject', () => {
51
51
  const { isPlainObject } = objects;
52
52
  it('should return true for plain JavaScript objects', () => {
53
- expect(isPlainObject({})).toBe(true);
53
+ expect(isPlainObject({})).toBe(false);
54
54
  expect(isPlainObject({ key: 'value' })).toBe(true);
55
55
  });
56
56
 
package/tsconfig.json CHANGED
@@ -26,7 +26,7 @@
26
26
 
27
27
  /* Modules */
28
28
  "module": "commonjs" /* Specify what module code is generated. */,
29
- // "rootDir": "./", /* Specify the root folder within your source files. */
29
+ "rootDir": "./src" /* Specify the root folder within your source files. */,
30
30
  // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
31
31
  // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
32
  // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
@@ -55,7 +55,7 @@
55
55
  // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
56
56
  // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
57
57
  // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
58
- "outDir": "lib" /* Specify an output folder for all emitted files. */,
58
+ "outDir": "./lib" /* Specify an output folder for all emitted files. */,
59
59
  // "removeComments": true, /* Disable emitting comments. */
60
60
  // "noEmit": true, /* Disable emitting files from a compilation. */
61
61
  // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
@@ -106,5 +106,5 @@
106
106
  // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
107
107
  "skipLibCheck": true /* Skip type checking all .d.ts files. */
108
108
  },
109
- "include": ["src/**/*"]
109
+ "include": ["src/**/*.ts"]
110
110
  }
package/index.ts DELETED
@@ -1,6 +0,0 @@
1
- // import arrays from './lib/arrays.js';
2
- import objects from './src/objects';
3
- // import routing from './lib/routing.js';
4
-
5
- // export { arrays, objects, routing };
6
- export { objects };
package/lib/arrays.d.ts DELETED
@@ -1,8 +0,0 @@
1
- type NumberFunction = (item: any) => number;
2
- type StringNumberFunction = (item: any) => string | number;
3
- type AnyFunction = (item: any) => any;
4
- declare const _default: {
5
- toMap: (items: any[], keyCallback: StringNumberFunction, valueFn?: AnyFunction, ignoreDuplicates?: boolean) => Map<any, any>;
6
- toIndexedArray: (items: any[], callback: NumberFunction) => any[];
7
- };
8
- export default _default;
package/lib/arrays.js DELETED
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const toMap = (items, keyCallback, valueFn = (item) => item, ignoreDuplicates = true) => {
4
- const map = new Map();
5
- items.forEach((item) => {
6
- const key = keyCallback(item);
7
- const value = valueFn ? valueFn(item) : item;
8
- if (ignoreDuplicates && map.has(key)) {
9
- }
10
- else {
11
- map.set(key, value);
12
- }
13
- });
14
- return map;
15
- };
16
- const toIndexedArray = (items, callback) => {
17
- const arr = [];
18
- items.forEach((item) => {
19
- // Check if item is an object and has a function named callback
20
- if (typeof item === 'object' && item !== null) {
21
- const index = callback(item);
22
- if (typeof index !== 'number') {
23
- throw new TypeError('Callback should return a number.');
24
- }
25
- arr[index] = item;
26
- }
27
- });
28
- return arr;
29
- };
30
- exports.default = { toMap, toIndexedArray };
package/lib/objects.d.ts DELETED
@@ -1,12 +0,0 @@
1
- type AnyObject = {
2
- [key: string]: any;
3
- };
4
- type NumberStringFunction = (key: string, item: any) => number | string;
5
- declare const _default: {
6
- isObject: (value: unknown) => boolean;
7
- isPlainObject: (value: unknown) => boolean;
8
- merge: (objects: AnyObject[], override?: boolean) => AnyObject;
9
- invert: (obj: Record<string | number, string | number>) => Record<string | number, string | number>;
10
- modifyKeys: (obj: AnyObject, callback: NumberStringFunction, ignoreDuplicates?: boolean) => AnyObject;
11
- };
12
- export default _default;
package/lib/objects.js DELETED
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const isObject = (value) => typeof value === 'object' && !Array.isArray(value) && value !== null;
4
- const isPlainObject = (value) => (value === null || value === void 0 ? void 0 : value.constructor.name) === 'Object';
5
- const merge = (objects, override = false) => {
6
- const merged = {};
7
- objects.forEach((obj) => {
8
- if (isObject(obj)) {
9
- const entries = Object.entries(obj);
10
- entries.forEach(([key, value]) => {
11
- if (!merged[key] || override)
12
- merged[key] = value;
13
- });
14
- }
15
- });
16
- return merged;
17
- };
18
- const invert = (obj) => {
19
- if (!isObject(obj)) {
20
- throw new Error('Invalid input: the input must be an object.');
21
- }
22
- const inverted = {};
23
- for (const [key, value] of Object.entries(obj)) {
24
- if (typeof value !== 'string' && typeof value !== 'number') {
25
- throw new Error('Invalid value type: the value must be a string or a number.');
26
- }
27
- inverted[value] = key;
28
- }
29
- return inverted;
30
- };
31
- const modifyKeys = (obj, callback, ignoreDuplicates = true) => {
32
- if (!isPlainObject(obj))
33
- throw new TypeError(`Invalid type of ${obj === null || obj === void 0 ? void 0 : obj.constructor.name}. Expected JavaScript object`);
34
- const entries = Object.entries(obj || {});
35
- const result = {};
36
- entries.forEach(([key, value]) => {
37
- const newKey = callback(key, value);
38
- if (!result.hasOwnProperty(newKey) || !ignoreDuplicates) {
39
- result[newKey] = value;
40
- }
41
- });
42
- return result;
43
- };
44
- exports.default = { isObject, isPlainObject, merge, invert, modifyKeys };
File without changes
File without changes
File without changes
File without changes
File without changes