rambda 10.0.0-beta.1 → 10.0.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/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "rambda",
3
- "version": "10.0.0-beta.1",
3
+ "version": "10.0.0",
4
4
  "scripts": {
5
- "out": "yarn populatedocs && yarn populatereadme && yarn immutable && yarn build && yarn create-docsify",
5
+ "out": "yarn populatedocs && yarn populatereadme && yarn build && yarn create-docsify",
6
6
  "build": "yarn build:main && yarn build:web && yarn build:esm",
7
7
  "build:main": "rollup rambda.js --file dist/rambda.cjs --format cjs",
8
8
  "build:esm": "rollup rambda.js --file dist/rambda.js --format es",
9
9
  "build:web": "rollup rambda.js --file dist/rambda.umd.js --format umd --name \"R\"",
10
- "immutable": "cd ../rambda-scripts && yarn immutable",
11
10
  "populatedocs": "cd ../rambda-scripts && yarn populate:docs",
12
11
  "populatereadme": "cd ../rambda-scripts && yarn populate:readme",
13
12
  "lint": "cd source && run lint:folder > lint-output.txt",
@@ -27,10 +26,12 @@
27
26
  ],
28
27
  "type": "module",
29
28
  "exports": {
30
- ".": {
31
- "import": "./dist/rambda.js",
32
- "require": "./dist/rambda.cjs"
33
- }
29
+ "require": {
30
+ "types": "./index.d.ts",
31
+ "default": "./dist/rambda.cjs"
32
+ },
33
+ "types": "./index.d.ts",
34
+ "default": "./dist/rambda.js"
34
35
  },
35
36
  "main": "dist/rambda.cjs",
36
37
  "module": "dist/rambda.js",
@@ -82,8 +83,6 @@
82
83
  "ts",
83
84
  "types",
84
85
  "typescript",
85
- "underscore",
86
- "util",
87
86
  "utilities",
88
87
  "utility",
89
88
  "utils"
@@ -94,9 +93,7 @@
94
93
  "src",
95
94
  "CHANGELOG.md",
96
95
  "index.d.ts",
97
- "immutable.d.ts",
98
- "rambda.js",
99
- "immutable.js"
96
+ "rambda.js"
100
97
  ],
101
98
  "sideEffects": false,
102
99
  "umd": "./dist/rambda.umd.js",
package/rambda.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /// <reference types="./index.d.ts" />
2
2
  export * from './src/addProp.js'
3
+ export * from './src/addPropToObjects.js'
3
4
  export * from './src/all.js'
4
5
  export * from './src/allPass.js'
5
6
  export * from './src/any.js'
@@ -33,6 +34,7 @@ export * from './src/findLastIndex.js'
33
34
  export * from './src/findNth.js'
34
35
  export * from './src/flatMap.js'
35
36
  export * from './src/flatten.js'
37
+ export * from './src/flattenObject.js'
36
38
  export * from './src/groupBy.js'
37
39
  export * from './src/head.js'
38
40
  export * from './src/includes.js'
@@ -56,6 +58,7 @@ export * from './src/maxBy.js'
56
58
  export * from './src/merge.js'
57
59
  export * from './src/mergeTypes.js'
58
60
  export * from './src/minBy.js'
61
+ export * from './src/modifyItemAtIndex.js'
59
62
  export * from './src/modifyProp.js'
60
63
  export * from './src/none.js'
61
64
  export * from './src/objOf.js'
@@ -64,6 +67,7 @@ export * from './src/omit.js'
64
67
  export * from './src/partition.js'
65
68
  export * from './src/partitionObject.js'
66
69
  export * from './src/path.js'
70
+ export * from './src/pathSatisfies.js'
67
71
  export * from './src/permutations.js'
68
72
  export * from './src/pick.js'
69
73
  export * from './src/pipe.js'
@@ -79,10 +83,12 @@ export * from './src/reduce.js'
79
83
  export * from './src/reject.js'
80
84
  export * from './src/rejectObject.js'
81
85
  export * from './src/replace.js'
82
- export * from './src/replaceItemAtIndex.js'
83
86
  export * from './src/shuffle.js'
84
87
  export * from './src/sort.js'
85
88
  export * from './src/sortBy.js'
89
+ export * from './src/sortByDescending.js'
90
+ export * from './src/sortByPath.js'
91
+ export * from './src/sortByPathDescending.js'
86
92
  export * from './src/sortObject.js'
87
93
  export * from './src/sortWith.js'
88
94
  export * from './src/split.js'
@@ -0,0 +1,14 @@
1
+ import { mapFn } from './map.js'
2
+
3
+ export function addPropToObjects (
4
+ property,
5
+ fn
6
+ ){
7
+ return listOfObjects => mapFn(
8
+ (obj) => ({
9
+ ...(obj),
10
+ [property]: fn(obj)
11
+ }),
12
+ listOfObjects
13
+ )
14
+ }
package/src/defaultTo.js CHANGED
@@ -2,10 +2,6 @@ function isFalsy(input) {
2
2
  return input === undefined || input === null || Number.isNaN(input) === true
3
3
  }
4
4
 
5
- export function defaultTo(defaultArgument, input) {
6
- if (arguments.length === 1) {
7
- return _input => defaultTo(defaultArgument, _input)
8
- }
9
-
10
- return isFalsy(input) ? defaultArgument : input
5
+ export function defaultTo(defaultArgument) {
6
+ return input => isFalsy(input) ? defaultArgument : input
11
7
  }
package/src/drop.js CHANGED
@@ -1,7 +1,3 @@
1
- export function drop(howManyToDrop, listOrString) {
2
- if (arguments.length === 1) {
3
- return _list => drop(howManyToDrop, _list)
4
- }
5
-
6
- return listOrString.slice(howManyToDrop > 0 ? howManyToDrop : 0)
1
+ export function drop(howManyToDrop, ) {
2
+ return list => list.slice(howManyToDrop > 0 ? howManyToDrop : 0)
7
3
  }
@@ -0,0 +1,76 @@
1
+ import { type } from './type.js'
2
+
3
+ export function flattenObjectHelper(obj, accumulator = []){
4
+ const willReturn = {}
5
+ Object.keys(obj).forEach(key => {
6
+ const typeIs = type(obj[ key ])
7
+ if (typeIs === 'Object'){
8
+ const [ flatResultValue, flatResultPath ] = flattenObjectHelper(obj[ key ],
9
+ [ ...accumulator, key ])
10
+ willReturn[ flatResultPath.join('.') ] = flatResultValue
11
+
12
+ return
13
+ } else if (accumulator.length > 0){
14
+ const finalKey = [ ...accumulator, key ].join('.')
15
+ willReturn[ finalKey ] = obj[ key ]
16
+
17
+ return
18
+ }
19
+ willReturn[ key ] = obj[ key ]
20
+ })
21
+ if (accumulator.length > 0) return [ willReturn, accumulator ]
22
+
23
+ return willReturn
24
+ }
25
+
26
+ export function transformFlatObject(obj){
27
+ const willReturn = {}
28
+
29
+ const transformFlatObjectFn = objLocal => {
30
+ const willReturnLocal = {}
31
+ Object.keys(objLocal).forEach(key => {
32
+ const typeIs = type(objLocal[ key ])
33
+ if (typeIs === 'Object'){
34
+ transformFlatObjectFn(objLocal[ key ])
35
+
36
+ return
37
+ }
38
+ willReturnLocal[ key ] = objLocal[ key ]
39
+ willReturn[ key ] = objLocal[ key ]
40
+ })
41
+
42
+ return willReturnLocal
43
+ }
44
+
45
+ Object.keys(obj).forEach(key => {
46
+ const typeIs = type(obj[ key ])
47
+ if (typeIs === 'Object'){
48
+ transformFlatObjectFn(obj[ key ], key)
49
+
50
+ return
51
+ }
52
+ willReturn[ key ] = obj[ key ]
53
+ })
54
+
55
+ return willReturn
56
+ }
57
+
58
+ export function flattenObject(obj){
59
+ const willReturn = {}
60
+
61
+ Object.keys(obj).forEach(key => {
62
+ const typeIs = type(obj[ key ])
63
+ if (typeIs === 'Object'){
64
+ const flatObject = flattenObjectHelper(obj[ key ])
65
+ const transformed = transformFlatObject(flatObject)
66
+
67
+ Object.keys(transformed).forEach(keyTransformed => {
68
+ willReturn[ `${ key }.${ keyTransformed }` ] = transformed[ keyTransformed ]
69
+ })
70
+ } else {
71
+ willReturn[ key ] = obj[ key ]
72
+ }
73
+ })
74
+
75
+ return willReturn
76
+ }
package/src/map.js CHANGED
@@ -1,11 +1,15 @@
1
+ export function mapFn(
2
+ fn, list
3
+ ){
4
+ let index = 0
5
+ const willReturn = Array(list.length)
6
+ while (index < list.length) {
7
+ willReturn[index] = fn(list[index], index)
8
+ index++
9
+ }
10
+ return willReturn
11
+ }
12
+
1
13
  export function map(fn) {
2
- return list => {
3
- let index = 0
4
- const willReturn = Array(list.length)
5
- while (index < list.length) {
6
- willReturn[index] = fn(list[index], index)
7
- index++
8
- }
9
- return willReturn
10
- }
14
+ return list => mapFn(fn, list)
11
15
  }
@@ -1,6 +1,6 @@
1
1
  import { cloneList } from './_internals/cloneList.js'
2
2
 
3
- export function replaceItemAtIndex(index, replaceFn) {
3
+ export function modifyItemAtIndex(index, replaceFn) {
4
4
  return list => {
5
5
  const actualIndex = index < 0 ? list.length + index : index
6
6
  if (index >= list.length || actualIndex < 0) {
package/src/path.js CHANGED
@@ -1,29 +1,27 @@
1
1
  import { createPath } from './_internals/createPath.js'
2
2
 
3
- export function path(pathInput, obj) {
4
- if (arguments.length === 1) {
5
- return _obj => path(pathInput, _obj)
6
- }
7
-
8
- if (!obj) {
9
- return undefined
10
- }
11
- let willReturn = obj
12
- let counter = 0
13
-
14
- const pathArrValue = createPath(pathInput)
15
-
16
- while (counter < pathArrValue.length) {
17
- if (willReturn === null || willReturn === undefined) {
18
- return undefined
19
- }
20
- if (willReturn[pathArrValue[counter]] === null) {
21
- return undefined
22
- }
23
-
24
- willReturn = willReturn[pathArrValue[counter]]
25
- counter++
26
- }
27
-
28
- return willReturn
3
+ export function path(pathInput) {
4
+ return (obj) => {
5
+ if (!obj) {
6
+ return undefined
7
+ }
8
+ let willReturn = obj
9
+ let counter = 0
10
+
11
+ const pathArrValue = createPath(pathInput)
12
+
13
+ while (counter < pathArrValue.length) {
14
+ if (willReturn === null || willReturn === undefined) {
15
+ return undefined
16
+ }
17
+ if (willReturn[pathArrValue[counter]] === null) {
18
+ return undefined
19
+ }
20
+
21
+ willReturn = willReturn[pathArrValue[counter]]
22
+ counter++
23
+ }
24
+
25
+ return willReturn
26
+ }
29
27
  }
@@ -0,0 +1,5 @@
1
+ import { path } from './path.js'
2
+
3
+ export function pathSatisfies(fn, pathInput) {
4
+ return obj => Boolean(fn(path(pathInput)(obj)))
5
+ }
package/src/propOr.js CHANGED
@@ -6,6 +6,6 @@ export function propOr(defaultValue, property) {
6
6
  return defaultValue
7
7
  }
8
8
 
9
- return defaultTo(defaultValue, obj[property])
9
+ return defaultTo(defaultValue)(obj[property])
10
10
  }
11
11
  }
package/src/range.js CHANGED
@@ -1,17 +1,29 @@
1
+ function rangeDescending(start, end) {
2
+ const len = start - end
3
+ const willReturn = Array(len)
4
+
5
+ for (let i = 0; i < len; i++) {
6
+ willReturn[i] = start - i
7
+ }
8
+
9
+ return willReturn
10
+ }
11
+
1
12
  export function range(start) {
2
13
  return end => {
3
14
  if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
4
15
  throw new TypeError('Both arguments to range must be numbers')
5
16
  }
6
17
 
7
- if (end <= start) {
18
+ if (end === start) {
8
19
  return []
9
20
  }
21
+ if (end < start) return rangeDescending(start,end)
10
22
 
11
23
  const len = end - start
12
24
  const willReturn = Array(len)
13
25
 
14
- for (let i = 0; i < len + 1; i++) {
26
+ for (let i = 0; i < len; i++) {
15
27
  willReturn[i] = start + i
16
28
  }
17
29
 
@@ -19,23 +31,4 @@ export function range(start) {
19
31
  }
20
32
  }
21
33
 
22
- export function rangeDescending(start) {
23
- return end => {
24
- if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
25
- throw new TypeError('Both arguments to range must be numbers')
26
- }
27
-
28
- if (end >= start) {
29
- return []
30
- }
31
34
 
32
- const len = start - end
33
- const willReturn = Array(len)
34
-
35
- for (let i = 0; i < len + 1; i++) {
36
- willReturn[i] = start - i
37
- }
38
-
39
- return willReturn
40
- }
41
- }
package/src/shuffle.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { cloneList } from './_internals/cloneList.js'
2
+
1
3
  export function shuffle(listInput) {
2
4
  const list = cloneList(listInput)
3
5
  let counter = list.length
package/src/sortBy.js CHANGED
@@ -1,18 +1,27 @@
1
1
  import { cloneList } from './_internals/cloneList.js'
2
2
 
3
- export function sortBy(sortFn) {
4
- return list => {
5
- const clone = cloneList(list)
3
+ export function sortByFn (
4
+ sortFn,
5
+ list,
6
+ descending
7
+ ){
8
+ const clone = cloneList(list)
9
+
10
+ return clone.sort((a, b) => {
11
+ const aSortResult = sortFn(a)
12
+ const bSortResult = sortFn(b)
6
13
 
7
- return clone.sort((a, b) => {
8
- const aSortResult = sortFn(a)
9
- const bSortResult = sortFn(b)
14
+ if (aSortResult === bSortResult) {
15
+ return 0
16
+ }
17
+ if(
18
+ descending
19
+ ) return aSortResult > bSortResult ? -1 : 1
10
20
 
11
- if (aSortResult === bSortResult) {
12
- return 0
13
- }
21
+ return aSortResult < bSortResult ? -1 : 1
22
+ })
23
+ }
14
24
 
15
- return aSortResult < bSortResult ? -1 : 1
16
- })
17
- }
25
+ export function sortBy(sortFn) {
26
+ return list => sortByFn(sortFn, list, false)
18
27
  }
@@ -0,0 +1,5 @@
1
+ import { sortByFn } from "./sortBy.js";
2
+
3
+ export function sortByDescending(sortFn) {
4
+ return list => sortByFn(sortFn, list, true)
5
+ }
@@ -0,0 +1,6 @@
1
+ import { path } from './path.js'
2
+ import { sortBy } from './sortBy.js'
3
+
4
+ export function sortByPath(sortPath) {
5
+ return list => sortBy(path(sortPath))(list)
6
+ }
@@ -0,0 +1,6 @@
1
+ import { path } from './path.js'
2
+ import { sortByDescending } from './sortByDescending.js'
3
+
4
+ export function sortByPathDescending(sortPath) {
5
+ return list => sortByDescending(path(sortPath))(list)
6
+ }