@feathersjs/commons
Advanced tools
Comparing version 4.5.11 to 5.0.0-beta.0
@@ -6,2 +6,39 @@ # Change Log | ||
# [5.0.0-beta.0](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.1...v5.0.0-beta.0) (2021-03-28) | ||
### Bug Fixes | ||
* Update Grant usage and other dependencies ([#2264](https://github.com/feathersjs/feathers/issues/2264)) ([7b0f8fa](https://github.com/feathersjs/feathers/commit/7b0f8fad252419ed0ad0bf259cdf3104d322ab60)) | ||
# [5.0.0-pre.1](https://github.com/feathersjs/feathers/compare/v4.5.11...v5.0.0-pre.1) (2020-12-17) | ||
# [5.0.0-pre.0](https://github.com/feathersjs/feathers/compare/v4.5.4...v5.0.0-pre.0) (2020-05-19) | ||
### Features | ||
* **core:** Migrate @feathersjs/feathers to TypeScript ([#1963](https://github.com/feathersjs/feathers/issues/1963)) ([7812529](https://github.com/feathersjs/feathers/commit/7812529ff0f1008e21211f1d01efbc49795dbe55)) | ||
* **core:** use @feathers/hooks and add async type ([#1929](https://github.com/feathersjs/feathers/issues/1929)) ([a5c4756](https://github.com/feathersjs/feathers/commit/a5c47562eae8410c82fe2f6308f26f8e78b6a3e8)) | ||
# [5.0.0-pre.0](https://github.com/feathersjs/feathers/compare/v4.5.4...v5.0.0-pre.0) (2020-05-19) | ||
### Features | ||
* **core:** Migrate @feathersjs/feathers to TypeScript ([#1963](https://github.com/feathersjs/feathers/issues/1963)) ([7812529](https://github.com/feathersjs/feathers/commit/7812529ff0f1008e21211f1d01efbc49795dbe55)) | ||
* **core:** use @feathers/hooks and add async type ([#1929](https://github.com/feathersjs/feathers/issues/1929)) ([a5c4756](https://github.com/feathersjs/feathers/commit/a5c47562eae8410c82fe2f6308f26f8e78b6a3e8)) | ||
## [4.5.11](https://github.com/feathersjs/feathers/compare/v4.5.10...v4.5.11) (2020-12-05) | ||
@@ -8,0 +45,0 @@ |
@@ -1,3 +0,21 @@ | ||
import * as hookUtils from './hooks'; | ||
export * from './utils'; | ||
export declare const hooks: typeof hookUtils; | ||
export declare function stripSlashes(name: string): string; | ||
export declare type KeyValueCallback<T> = (value: any, key: string) => T; | ||
export declare const _: { | ||
each(obj: any, callback: KeyValueCallback<void>): void; | ||
some(value: any, callback: KeyValueCallback<boolean>): boolean; | ||
every(value: any, callback: KeyValueCallback<boolean>): boolean; | ||
keys(obj: any): string[]; | ||
values(obj: any): any[]; | ||
isMatch(obj: any, item: any): boolean; | ||
isEmpty(obj: any): boolean; | ||
isObject(item: any): boolean; | ||
isObjectOrArray(value: any): boolean; | ||
extend(first: any, ...rest: any[]): any; | ||
omit(obj: any, ...keys: string[]): any; | ||
pick(source: any, ...keys: string[]): { | ||
[key: string]: any; | ||
}; | ||
merge(target: any, source: any): any; | ||
}; | ||
export declare function isPromise(result: any): boolean; | ||
export declare function createSymbol(name: string): string | symbol; |
114
lib/index.js
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createSymbol = exports.isPromise = exports._ = exports.stripSlashes = void 0; | ||
// Removes all leading and trailing slashes from a path | ||
function stripSlashes(name) { | ||
return name.replace(/^(\/+)|(\/+)$/g, ''); | ||
} | ||
exports.stripSlashes = stripSlashes; | ||
// A set of lodash-y utility functions that use ES6 | ||
exports._ = { | ||
each(obj, callback) { | ||
if (obj && typeof obj.forEach === 'function') { | ||
obj.forEach(callback); | ||
} | ||
else if (exports._.isObject(obj)) { | ||
Object.keys(obj).forEach(key => callback(obj[key], key)); | ||
} | ||
}, | ||
some(value, callback) { | ||
return Object.keys(value) | ||
.map(key => [value[key], key]) | ||
.some(([val, key]) => callback(val, key)); | ||
}, | ||
every(value, callback) { | ||
return Object.keys(value) | ||
.map(key => [value[key], key]) | ||
.every(([val, key]) => callback(val, key)); | ||
}, | ||
keys(obj) { | ||
return Object.keys(obj); | ||
}, | ||
values(obj) { | ||
return exports._.keys(obj).map(key => obj[key]); | ||
}, | ||
isMatch(obj, item) { | ||
return exports._.keys(item).every(key => obj[key] === item[key]); | ||
}, | ||
isEmpty(obj) { | ||
return exports._.keys(obj).length === 0; | ||
}, | ||
isObject(item) { | ||
return (typeof item === 'object' && !Array.isArray(item) && item !== null); | ||
}, | ||
isObjectOrArray(value) { | ||
return typeof value === 'object' && value !== null; | ||
}, | ||
extend(first, ...rest) { | ||
return Object.assign(first, ...rest); | ||
}, | ||
omit(obj, ...keys) { | ||
const result = exports._.extend({}, obj); | ||
keys.forEach(key => delete result[key]); | ||
return result; | ||
}, | ||
pick(source, ...keys) { | ||
return keys.reduce((result, key) => { | ||
if (source[key] !== undefined) { | ||
result[key] = source[key]; | ||
} | ||
return result; | ||
}, {}); | ||
}, | ||
// Recursively merge the source object into the target object | ||
merge(target, source) { | ||
if (exports._.isObject(target) && exports._.isObject(source)) { | ||
Object.keys(source).forEach(key => { | ||
if (exports._.isObject(source[key])) { | ||
if (!target[key]) { | ||
Object.assign(target, { [key]: {} }); | ||
} | ||
exports._.merge(target[key], source[key]); | ||
} | ||
else { | ||
Object.assign(target, { [key]: source[key] }); | ||
} | ||
}); | ||
} | ||
return target; | ||
} | ||
}; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.hooks = void 0; | ||
const hookUtils = __importStar(require("./hooks")); | ||
__exportStar(require("./utils"), exports); | ||
exports.hooks = hookUtils; | ||
// Duck-checks if an object looks like a promise | ||
function isPromise(result) { | ||
return exports._.isObject(result) && | ||
typeof result.then === 'function'; | ||
} | ||
exports.isPromise = isPromise; | ||
function createSymbol(name) { | ||
return typeof Symbol !== 'undefined' ? Symbol(name) : name; | ||
} | ||
exports.createSymbol = createSymbol; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@feathersjs/commons", | ||
"version": "4.5.11", | ||
"version": "5.0.0-beta.0", | ||
"description": "Shared Feathers utility functions", | ||
@@ -28,3 +28,3 @@ "homepage": "https://feathersjs.com", | ||
"engines": { | ||
"node": ">= 10" | ||
"node": ">= 12" | ||
}, | ||
@@ -45,3 +45,3 @@ "main": "lib/", | ||
"compile": "shx rm -rf lib/ && tsc", | ||
"test": "mocha --config ../../.mocharc.ts.json --recursive test/**.test.ts test/**/*.test.ts" | ||
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts" | ||
}, | ||
@@ -55,10 +55,10 @@ "directories": { | ||
"devDependencies": { | ||
"@types/mocha": "^8.0.4", | ||
"@types/node": "^14.14.10", | ||
"mocha": "^8.2.1", | ||
"@types/mocha": "^8.2.2", | ||
"@types/node": "^14.14.37", | ||
"mocha": "^8.3.2", | ||
"shx": "^0.3.3", | ||
"ts-node": "^9.1.0", | ||
"typescript": "^4.1.2" | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.2.3" | ||
}, | ||
"gitHead": "de0526849eb36ab6ef19ef1764e0d9e0a6ccbd81" | ||
"gitHead": "3b953f85cc1c2184a032bebac302f8de8a2f0d4d" | ||
} |
103
src/index.ts
@@ -1,4 +0,101 @@ | ||
import * as hookUtils from './hooks'; | ||
// Removes all leading and trailing slashes from a path | ||
export function stripSlashes (name: string) { | ||
return name.replace(/^(\/+)|(\/+)$/g, ''); | ||
} | ||
export * from './utils'; | ||
export const hooks = hookUtils; | ||
export type KeyValueCallback<T> = (value: any, key: string) => T; | ||
// A set of lodash-y utility functions that use ES6 | ||
export const _ = { | ||
each (obj: any, callback: KeyValueCallback<void>) { | ||
if (obj && typeof obj.forEach === 'function') { | ||
obj.forEach(callback); | ||
} else if (_.isObject(obj)) { | ||
Object.keys(obj).forEach(key => callback(obj[key], key)); | ||
} | ||
}, | ||
some (value: any, callback: KeyValueCallback<boolean>) { | ||
return Object.keys(value) | ||
.map(key => [ value[key], key ]) | ||
.some(([val, key]) => callback(val, key)); | ||
}, | ||
every (value: any, callback: KeyValueCallback<boolean>) { | ||
return Object.keys(value) | ||
.map(key => [ value[key], key ]) | ||
.every(([val, key]) => callback(val, key)); | ||
}, | ||
keys (obj: any) { | ||
return Object.keys(obj); | ||
}, | ||
values (obj: any) { | ||
return _.keys(obj).map(key => obj[key]); | ||
}, | ||
isMatch (obj: any, item: any) { | ||
return _.keys(item).every(key => obj[key] === item[key]); | ||
}, | ||
isEmpty (obj: any) { | ||
return _.keys(obj).length === 0; | ||
}, | ||
isObject (item: any) { | ||
return (typeof item === 'object' && !Array.isArray(item) && item !== null); | ||
}, | ||
isObjectOrArray (value: any) { | ||
return typeof value === 'object' && value !== null; | ||
}, | ||
extend (first: any, ...rest: any[]) { | ||
return Object.assign(first, ...rest); | ||
}, | ||
omit (obj: any, ...keys: string[]) { | ||
const result = _.extend({}, obj); | ||
keys.forEach(key => delete result[key]); | ||
return result; | ||
}, | ||
pick (source: any, ...keys: string[]) { | ||
return keys.reduce((result: { [key: string]: any }, key) => { | ||
if (source[key] !== undefined) { | ||
result[key] = source[key]; | ||
} | ||
return result; | ||
}, {}); | ||
}, | ||
// Recursively merge the source object into the target object | ||
merge (target: any, source: any) { | ||
if (_.isObject(target) && _.isObject(source)) { | ||
Object.keys(source).forEach(key => { | ||
if (_.isObject(source[key])) { | ||
if (!target[key]) { | ||
Object.assign(target, { [key]: {} }); | ||
} | ||
_.merge(target[key], source[key]); | ||
} else { | ||
Object.assign(target, { [key]: source[key] }); | ||
} | ||
}); | ||
} | ||
return target; | ||
} | ||
}; | ||
// Duck-checks if an object looks like a promise | ||
export function isPromise (result: any) { | ||
return _.isObject(result) && | ||
typeof result.then === 'function'; | ||
} | ||
export function createSymbol (name: string) { | ||
return typeof Symbol !== 'undefined' ? Symbol(name) : name; | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
39957
70746
8
194
1
1