@jamesrock/rockjs 1.14.0 → 1.15.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.
Files changed (2) hide show
  1. package/index.js +40 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -25,6 +25,46 @@ export const getTimeString = (type = 'short') => new Date().toLocaleTimeString('
25
25
  export const getDateTimeString = (type = 'short') => `${getDateString(type)} ${getTimeString(type)}`;
26
26
  export const isValidKey = (key, options) => options.includes(key);
27
27
  export const makeArray = (length, mapper = (a, i) => i) => Array.from({length}, mapper);
28
+ export const floorTo = (number, to) => (Math.floor(number*to)/to);
29
+ export const roundTo = (number, to) => (Math.round(number*to)/to);
30
+ export const ceilTo = (number, to) => (Math.ceil(number*to)/to);
31
+ export const getXPercentOfY = (x, y) => (y*(x/100));
32
+ export const getXAsPercentOfY = (x, y) => ((x/y)*100);
33
+
34
+ const sortingMethods = {
35
+ '0-9': (prop) => (a, b) => prop(a)-prop(b),
36
+ '9-0': (prop) => (a, b) => prop(b)-prop(a),
37
+ 'A-Z': (prop) => (a, b) => {
38
+ a = prop(a);
39
+ b = prop(b);
40
+ if(a<b) {
41
+ return -1;
42
+ }
43
+ else if(a>b) {
44
+ return 1;
45
+ }
46
+ else {
47
+ return 0;
48
+ };
49
+ },
50
+ 'Z-A': (prop) => (a, b) => {
51
+ a = prop(a);
52
+ b = prop(b);
53
+ if(b<a) {
54
+ return -1;
55
+ }
56
+ else if(b>a) {
57
+ return 1;
58
+ }
59
+ else {
60
+ return 0;
61
+ };
62
+ }
63
+ };
64
+
65
+ export const sort = (target, prop, method) => {
66
+ return target.sort(sortingMethods[method](prop));
67
+ };
28
68
 
29
69
  export const setDocumentHeight = () => {
30
70
  document.documentElement.style.height = window.navigator.standalone ? '100vh' : '100svh';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamesrock/rockjs",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "description": "utility bliss",
5
5
  "license": "ISC",
6
6
  "author": "James Rock",