@gkucmierz/utils 1.23.1 → 1.24.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/main.mjs CHANGED
@@ -11,6 +11,9 @@ import {
11
11
  import {
12
12
  binarySearchArr
13
13
  } from './src/binary-search.mjs'
14
+ import {
15
+ copyCase
16
+ } from './src/copy-case.mjs'
14
17
  import {
15
18
  egcd
16
19
  } from './src/egcd.mjs'
@@ -67,6 +70,7 @@ export * from './src/SetCnt.mjs';
67
70
  export * from './src/base64.mjs';
68
71
  export * from './src/bijective-numeration.mjs';
69
72
  export * from './src/binary-search.mjs';
73
+ export * from './src/copy-case.mjs';
70
74
  export * from './src/egcd.mjs';
71
75
  export * from './src/factors.mjs';
72
76
  export * from './src/gcd.mjs';
@@ -86,5 +90,5 @@ export * from './src/square-root.mjs';
86
90
  export * from './src/tonelli-shanks.mjs';
87
91
 
88
92
  export default [
89
- SetCnt, fromBase64, fromBase64Url, toBase64, toBase64Url, bijective2num, bijective2numBI, num2bijective, num2bijectiveBI, binarySearchArr, egcd, factors, factorsBI, gcd, gcdBI, getType, gpn, gpnBI, Heap, heronsFormula, heronsFormulaBI, lcm, lcmBI, ListNode, matrixAsArray, memoize, mod, modBI, phi, phiBI, powMod, powModBI, array2range, range2array, squareRoot, squareRootBI, tonelliShanksBI
93
+ SetCnt, fromBase64, fromBase64Url, toBase64, toBase64Url, bijective2num, bijective2numBI, num2bijective, num2bijectiveBI, binarySearchArr, copyCase, egcd, factors, factorsBI, gcd, gcdBI, getType, gpn, gpnBI, Heap, heronsFormula, heronsFormulaBI, lcm, lcmBI, ListNode, matrixAsArray, memoize, mod, modBI, phi, phiBI, powMod, powModBI, array2range, range2array, squareRoot, squareRootBI, tonelliShanksBI
90
94
  ];
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@gkucmierz/utils",
3
- "version": "1.23.1",
3
+ "version": "1.24.0",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@gkucmierz/utils",
9
- "version": "1.23.1",
9
+ "version": "1.24.0",
10
10
  "license": "MIT",
11
11
  "devDependencies": {
12
12
  "husky": "^8.0.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gkucmierz/utils",
3
- "version": "1.23.1",
3
+ "version": "1.24.0",
4
4
  "description": "Usefull functions for solving programming tasks",
5
5
  "main": "main.mjs",
6
6
  "scripts": {
@@ -0,0 +1,12 @@
1
+
2
+ import {
3
+ copyCase,
4
+ } from '../src/copy-case.mjs';
5
+
6
+ describe('copy-case', () => {
7
+ it('few tests', () => {
8
+ expect(copyCase('styczeń', 'january')).toBe('styczeń');
9
+ expect(copyCase('styczeń', 'January')).toBe('Styczeń');
10
+ expect(copyCase('styczeń', 'JANUARY')).toBe('STYCZEŃ');
11
+ });
12
+ });
@@ -0,0 +1,12 @@
1
+
2
+
3
+ export const copyCase = (word, from) => {
4
+ const isLower = w => w.toLowerCase() === w;
5
+ const isUpper = w => w.toUpperCase() === w;
6
+ if (isLower(from)) return word.toLowerCase();
7
+ if (isUpper(from)) return word.toUpperCase();
8
+ if (isUpper(from[0]) && isLower(from.slice(1))) {
9
+ return word[0].toUpperCase() + word.slice(1).toLowerCase();
10
+ }
11
+ return word;
12
+ };