cafe-utility 2.0.0 → 2.2.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 +29 -9
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -498,6 +498,11 @@ const unshiftAndLimit = (array, item, limit) => {
498
498
  }
499
499
  }
500
500
 
501
+ const atRolling = (array, index) => {
502
+ const realIndex = index % array.length
503
+ return array[realIndex]
504
+ }
505
+
501
506
  const pushAll = (array, elements) => Array.prototype.push.apply(array, elements)
502
507
 
503
508
  const unshiftAll = (array, elements) => Array.prototype.unshift.apply(array, elements)
@@ -647,6 +652,19 @@ const camelToTitle = string => capitalize(string.replace(/([A-Z])/g, ' $1'))
647
652
 
648
653
  const slugToTitle = string => string.split('-').map(capitalize).join(' ')
649
654
 
655
+ const joinHumanly = (parts, separator = ', ', lastSeparator = ' and ') => {
656
+ if (!parts || !parts.length) {
657
+ return null
658
+ }
659
+ if (parts.length === 1) {
660
+ return parts[0]
661
+ }
662
+ if (parts.length === 2) {
663
+ return `${parts[0]}${lastSeparator}${parts[1]}`
664
+ }
665
+ return `${parts.slice(0, parts.length - 1).join(separator)}${lastSeparator}${parts[parts.length - 1]}`
666
+ }
667
+
650
668
  const surroundInOut = (string, filler) => filler + string.split('').join(filler) + filler
651
669
 
652
670
  const enumify = string => slugify(string).replace(/-/g, '_').toUpperCase()
@@ -946,13 +964,13 @@ const getProgress = (startedAt, current, total) => {
946
964
  }
947
965
 
948
966
  const dayNumberIndex = {
949
- 0: 'monday',
950
- 1: 'tuesday',
951
- 2: 'wednesday',
952
- 3: 'thursday',
953
- 4: 'friday',
954
- 5: 'saturday',
955
- 6: 'sunday'
967
+ 0: 'sunday',
968
+ 1: 'monday',
969
+ 2: 'tuesday',
970
+ 3: 'wednesday',
971
+ 4: 'thursday',
972
+ 5: 'friday',
973
+ 6: 'saturday'
956
974
  }
957
975
 
958
976
  const mapDayNumber = zeroBasedIndex => ({
@@ -1425,7 +1443,8 @@ module.exports = {
1425
1443
  merge: mergeArrays,
1426
1444
  empty,
1427
1445
  pushToBucket,
1428
- unshiftAndLimit
1446
+ unshiftAndLimit,
1447
+ atRolling
1429
1448
  },
1430
1449
  System: {
1431
1450
  sleepMillis,
@@ -1583,7 +1602,8 @@ module.exports = {
1583
1602
  normalizeFilename,
1584
1603
  parseFilename,
1585
1604
  camelToTitle,
1586
- slugToTitle
1605
+ slugToTitle,
1606
+ joinHumanly
1587
1607
  },
1588
1608
  Assertions: {
1589
1609
  asEqual,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {