mielk-fn 1.0.7 → 1.0.9

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.
@@ -5,6 +5,7 @@ type NumberStringFunction = (key: string, item: any) => number | string;
5
5
  declare const _default: {
6
6
  isObject: (value: unknown) => boolean;
7
7
  isPlainObject: (value: unknown) => boolean;
8
+ isPrimitive: (value: any) => boolean;
8
9
  merge: (objects: AnyObject[], override?: boolean) => AnyObject;
9
10
  invert: (obj: Record<string | number, string | number>) => Record<string | number, string | number>;
10
11
  modifyKeys: (obj: AnyObject, callback: NumberStringFunction, ignoreDuplicates?: boolean) => AnyObject;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const isObject = (value) => typeof value === 'object' && !Array.isArray(value) && value !== null;
4
4
  const isPlainObject = (value) => (value === null || value === void 0 ? void 0 : value.constructor.name) === 'Object';
5
+ const isPrimitive = (value) => value !== Object(value);
5
6
  const merge = (objects, override = false) => {
6
7
  const merged = {};
7
8
  objects.forEach((obj) => {
@@ -41,4 +42,4 @@ const modifyKeys = (obj, callback, ignoreDuplicates = true) => {
41
42
  });
42
43
  return result;
43
44
  };
44
- exports.default = { isObject, isPlainObject, merge, invert, modifyKeys };
45
+ exports.default = { isObject, isPlainObject, isPrimitive, merge, invert, modifyKeys };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const clear = (value) => {
4
- const regex = /(^\s|(?<=\s)\s|\s$)/gi;
4
+ const regex = /(^\s+|(?<=\s)\s|\s+$)/gi;
5
5
  return value.replace(regex, '');
6
6
  };
7
7
  exports.default = { clear };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mielk-fn",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Set of helpful functions",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -5,6 +5,8 @@ const isObject = (value: unknown) => typeof value === 'object' && !Array.isArray
5
5
 
6
6
  const isPlainObject = (value: unknown) => value?.constructor.name === 'Object';
7
7
 
8
+ const isPrimitive = (value: any) => value !== Object(value);
9
+
8
10
  const merge = (objects: AnyObject[], override: boolean = false): AnyObject => {
9
11
  const merged: AnyObject = {};
10
12
  objects.forEach((obj) => {
@@ -52,4 +54,4 @@ const modifyKeys = (obj: AnyObject, callback: NumberStringFunction, ignoreDuplic
52
54
  return result;
53
55
  };
54
56
 
55
- export default { isObject, isPlainObject, merge, invert, modifyKeys };
57
+ export default { isObject, isPlainObject, isPrimitive, merge, invert, modifyKeys };
@@ -1,5 +1,5 @@
1
1
  const clear = (value: string): string => {
2
- const regex = /(^\s|(?<=\s)\s|\s$)/gi;
2
+ const regex = /(^\s+|(?<=\s)\s|\s+$)/gi;
3
3
  return value.replace(regex, '');
4
4
  };
5
5
 
@@ -68,6 +68,48 @@ describe('isPlainObject', () => {
68
68
  });
69
69
  });
70
70
 
71
+ describe('isPrimitive', () => {
72
+ const { isPrimitive } = objects;
73
+ test('isPrimitive should return true for string', () => {
74
+ expect(isPrimitive('Hello')).toBe(true);
75
+ });
76
+
77
+ test('isPrimitive should return true for number', () => {
78
+ expect(isPrimitive(123)).toBe(true);
79
+ });
80
+
81
+ test('isPrimitive should return true for boolean', () => {
82
+ expect(isPrimitive(true)).toBe(true);
83
+ expect(isPrimitive(false)).toBe(true);
84
+ });
85
+
86
+ test('isPrimitive should return true for null', () => {
87
+ expect(isPrimitive(null)).toBe(true);
88
+ });
89
+
90
+ test('isPrimitive should return true for undefined', () => {
91
+ expect(isPrimitive(undefined)).toBe(true);
92
+ });
93
+
94
+ test('isPrimitive should return true for symbol', () => {
95
+ expect(isPrimitive(Symbol('symbol'))).toBe(true);
96
+ });
97
+
98
+ test('isPrimitive should return false for object', () => {
99
+ expect(isPrimitive({})).toBe(false);
100
+ expect(isPrimitive({ key: 'value' })).toBe(false);
101
+ });
102
+
103
+ test('isPrimitive should return false for array', () => {
104
+ expect(isPrimitive([])).toBe(false);
105
+ expect(isPrimitive([1, 2, 3])).toBe(false);
106
+ });
107
+
108
+ test('isPrimitive should return false for function', () => {
109
+ expect(isPrimitive(() => {})).toBe(false);
110
+ });
111
+ });
112
+
71
113
  describe('merge', () => {
72
114
  const merge = objects.merge;
73
115
  test('Empty array', () => {
@@ -0,0 +1,34 @@
1
+ import strings from '../src/methods/strings';
2
+
3
+ describe('clear', () => {
4
+ const { clear } = strings;
5
+ test('clear should remove leading and trailing spaces', () => {
6
+ expect(clear(' Hello world ')).toBe('Hello world');
7
+ });
8
+
9
+ test('clear should remove multiple spaces inside the string', () => {
10
+ expect(clear('Hello world')).toBe('Hello world');
11
+ });
12
+
13
+ test('clear should return the same string if no extra spaces', () => {
14
+ expect(clear('Hello world')).toBe('Hello world');
15
+ });
16
+
17
+ test('clear should return empty string if input string contains only spaces', () => {
18
+ expect(clear(' ')).toBe('');
19
+ });
20
+
21
+ test('clear should throw an error if input is not a string', () => {
22
+ expect(() => {
23
+ clear(123 as unknown as string);
24
+ }).toThrow();
25
+ });
26
+
27
+ test('clear should handle string with only one word correctly', () => {
28
+ expect(clear(' Hello ')).toBe('Hello');
29
+ });
30
+
31
+ test('clear should handle empty string correctly', () => {
32
+ expect(clear('')).toBe('');
33
+ });
34
+ });