Comparing version 0.0.19 to 0.0.20
@@ -11,3 +11,3 @@ /** | ||
*/ | ||
export declare function compact<T>(items: readonly T[]): T[]; | ||
export declare function compact<T>(items: readonly (T | null | undefined | false | '' | 0)[]): T[]; | ||
//# sourceMappingURL=compact.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function isTruthy(value) { | ||
return !!value; | ||
} | ||
/** | ||
@@ -15,4 +18,4 @@ * Filter out all falsey values. The values `false`, `null`, `0`, `""`, `undefined`, and `NaN` are falsey. | ||
// TODO: Make lazy version | ||
return items.filter(function (x) { return !!x; }); | ||
return items.filter(isTruthy); | ||
} | ||
exports.compact = compact; |
@@ -9,5 +9,6 @@ "use strict"; | ||
var items = [false, null, 0, '', undefined, NaN, true, 1, 'a']; | ||
expect(compact_1.compact(items)).toEqual([true, 1, 'a']); | ||
var results = compact_1.compact(items); | ||
expect(results).toEqual([true, 1, 'a']); | ||
}); | ||
// test('lazy', () => { | ||
// }) |
@@ -17,4 +17,6 @@ "use strict"; | ||
var copy = __spreadArrays(array); | ||
copy.splice(-n); | ||
if (n !== 0) { | ||
copy.splice(-n); | ||
} | ||
return copy; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var dropLast_1 = require("./dropLast"); | ||
var arr = [1, 2, 3, 4, 5]; | ||
test('should drop last', function () { | ||
var arr = [1, 2, 3, 4, 5]; | ||
expect(dropLast_1.dropLast(arr, 2)).toEqual([1, 2, 3]); | ||
}); | ||
test('should not drop last', function () { | ||
expect(dropLast_1.dropLast(arr, 0)).toEqual(arr); | ||
expect(dropLast_1.dropLast(arr, -0)).toEqual(arr); | ||
}); |
@@ -13,3 +13,3 @@ /** | ||
* @data_first | ||
* @category Array | ||
* @category Object | ||
*/ | ||
@@ -29,5 +29,5 @@ export declare function equals(a: any, b: any): boolean; | ||
* @data_last | ||
* @category Array | ||
* @category Object | ||
*/ | ||
export declare function equals(a: any): (b: any) => boolean; | ||
//# sourceMappingURL=equals.d.ts.map |
export * from './addProp'; | ||
export * from './allPass'; | ||
export * from './anyPass'; | ||
@@ -3,0 +4,0 @@ export * from './chunk'; |
@@ -7,2 +7,3 @@ "use strict"; | ||
__export(require("./addProp")); | ||
__export(require("./allPass")); | ||
__export(require("./anyPass")); | ||
@@ -9,0 +10,0 @@ __export(require("./chunk")); |
@@ -11,3 +11,3 @@ /** | ||
*/ | ||
export declare function compact<T>(items: readonly T[]): T[]; | ||
export declare function compact<T>(items: readonly (T | null | undefined | false | '' | 0)[]): T[]; | ||
//# sourceMappingURL=compact.d.ts.map |
@@ -0,1 +1,4 @@ | ||
function isTruthy(value) { | ||
return !!value; | ||
} | ||
/** | ||
@@ -13,3 +16,3 @@ * Filter out all falsey values. The values `false`, `null`, `0`, `""`, `undefined`, and `NaN` are falsey. | ||
// TODO: Make lazy version | ||
return items.filter(function (x) { return !!x; }); | ||
return items.filter(isTruthy); | ||
} |
@@ -7,5 +7,6 @@ import { compact } from './compact'; | ||
var items = [false, null, 0, '', undefined, NaN, true, 1, 'a']; | ||
expect(compact(items)).toEqual([true, 1, 'a']); | ||
var results = compact(items); | ||
expect(results).toEqual([true, 1, 'a']); | ||
}); | ||
// test('lazy', () => { | ||
// }) |
@@ -14,4 +14,6 @@ var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
var copy = __spreadArrays(array); | ||
copy.splice(-n); | ||
if (n !== 0) { | ||
copy.splice(-n); | ||
} | ||
return copy; | ||
} |
import { dropLast } from './dropLast'; | ||
var arr = [1, 2, 3, 4, 5]; | ||
test('should drop last', function () { | ||
var arr = [1, 2, 3, 4, 5]; | ||
expect(dropLast(arr, 2)).toEqual([1, 2, 3]); | ||
}); | ||
test('should not drop last', function () { | ||
expect(dropLast(arr, 0)).toEqual(arr); | ||
expect(dropLast(arr, -0)).toEqual(arr); | ||
}); |
@@ -13,3 +13,3 @@ /** | ||
* @data_first | ||
* @category Array | ||
* @category Object | ||
*/ | ||
@@ -29,5 +29,5 @@ export declare function equals(a: any, b: any): boolean; | ||
* @data_last | ||
* @category Array | ||
* @category Object | ||
*/ | ||
export declare function equals(a: any): (b: any) => boolean; | ||
//# sourceMappingURL=equals.d.ts.map |
export * from './addProp'; | ||
export * from './allPass'; | ||
export * from './anyPass'; | ||
@@ -3,0 +4,0 @@ export * from './chunk'; |
export * from './addProp'; | ||
export * from './allPass'; | ||
export * from './anyPass'; | ||
@@ -3,0 +4,0 @@ export * from './chunk'; |
{ | ||
"name": "remeda", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"description": "A utility library for JavaScript and Typescript.", | ||
@@ -5,0 +5,0 @@ "main": "dist/commonjs/index.js", |
@@ -8,3 +8,4 @@ import { compact } from './compact'; | ||
const items = [false, null, 0, '', undefined, NaN, true, 1, 'a'] as const; | ||
expect(compact(items)).toEqual([true, 1, 'a']); | ||
const results: (boolean | number | 'a')[] = compact(items); | ||
expect(results).toEqual([true, 1, 'a']); | ||
}); | ||
@@ -11,0 +12,0 @@ |
@@ -0,1 +1,5 @@ | ||
function isTruthy<T>(value: T | null | undefined | false | '' | 0): value is T { | ||
return !!value; | ||
} | ||
/** | ||
@@ -11,5 +15,7 @@ * Filter out all falsey values. The values `false`, `null`, `0`, `""`, `undefined`, and `NaN` are falsey. | ||
*/ | ||
export function compact<T>(items: readonly T[]) { | ||
export function compact<T>( | ||
items: readonly (T | null | undefined | false | '' | 0)[] | ||
): T[] { | ||
// TODO: Make lazy version | ||
return items.filter(x => !!x); | ||
return items.filter(isTruthy); | ||
} |
import { dropLast } from './dropLast'; | ||
const arr = [1, 2, 3, 4, 5] as const; | ||
test('should drop last', () => { | ||
const arr = [1, 2, 3, 4, 5] as const; | ||
expect(dropLast(arr, 2)).toEqual([1, 2, 3]); | ||
}); | ||
test('should not drop last', () => { | ||
expect(dropLast(arr, 0)).toEqual(arr); | ||
expect(dropLast(arr, -0)).toEqual(arr); | ||
}); |
@@ -35,4 +35,6 @@ import { purry } from './purry'; | ||
const copy = [...array]; | ||
copy.splice(-n); | ||
if (n !== 0) { | ||
copy.splice(-n) | ||
} | ||
return copy; | ||
} |
@@ -20,3 +20,3 @@ import { purry } from './purry'; | ||
* @data_first | ||
* @category Array | ||
* @category Object | ||
*/ | ||
@@ -37,3 +37,3 @@ export function equals(a: any, b: any): boolean; | ||
* @data_last | ||
* @category Array | ||
* @category Object | ||
*/ | ||
@@ -40,0 +40,0 @@ export function equals(a: any): (b: any) => boolean; |
export * from './addProp'; | ||
export * from './allPass'; | ||
export * from './anyPass'; | ||
@@ -3,0 +4,0 @@ export * from './chunk'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1222580
42612