Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@poppinss/utils

Package Overview
Dependencies
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@poppinss/utils - npm Package Compare versions

Comparing version 3.2.1 to 3.3.0

build/src/flatten.d.ts

1

build/index.d.ts
export * as lodash from './src/lodash';
export { slash } from './src/slash';
export { flatten } from './src/flatten';
export { Exception } from './src/Exception';

@@ -4,0 +5,0 @@ export { safeParse } from './src/safeParse';

4

build/index.js

@@ -30,6 +30,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.ManagerConfigValidator = exports.defineStaticProperty = exports.safeStringify = exports.esmResolver = exports.esmRequire = exports.safeParse = exports.Exception = exports.slash = exports.lodash = void 0;
exports.ManagerConfigValidator = exports.defineStaticProperty = exports.safeStringify = exports.esmResolver = exports.esmRequire = exports.safeParse = exports.Exception = exports.flatten = exports.slash = exports.lodash = void 0;
exports.lodash = __importStar(require("./src/lodash"));
var slash_1 = require("./src/slash");
Object.defineProperty(exports, "slash", { enumerable: true, get: function () { return slash_1.slash; } });
var flatten_1 = require("./src/flatten");
Object.defineProperty(exports, "flatten", { enumerable: true, get: function () { return flatten_1.flatten; } });
var Exception_1 = require("./src/Exception");

@@ -36,0 +38,0 @@ Object.defineProperty(exports, "Exception", { enumerable: true, get: function () { return Exception_1.Exception; } });

@@ -6,4 +6,4 @@ /**

*/
export declare function requireAll(location: string, recursive?: boolean, optional?: boolean): {
export declare function requireAll(location: string, recursive?: boolean, optional?: boolean, filter?: (file: string) => boolean | string): {
[key: string]: any;
} | undefined;

@@ -20,10 +20,6 @@ "use strict";

/**
* Function to filter selected files only
* Function to filter and keep script files only
*/
function fileFilter(file) {
const ext = (0, path_1.extname)(file);
if (!(0, isScriptFile_1.isScriptFile)(file)) {
return false;
}
return file.replace(new RegExp(`${ext}$`), '');
return (0, isScriptFile_1.isScriptFile)(file);
}

@@ -35,3 +31,3 @@ /**

*/
function requireAll(location, recursive = true, optional = false) {
function requireAll(location, recursive = true, optional = false, filter = fileFilter) {
try {

@@ -41,3 +37,20 @@ return (0, require_all_1.default)({

recursive,
filter: fileFilter,
filter: (file) => {
let result = true;
/**
* Invoke user defined function
*/
if (typeof filter === 'function') {
result = filter(file);
}
/**
* Use the default file name when file is meant to
* be kept
*/
if (result === true) {
const ext = (0, path_1.extname)(file);
return file.replace(new RegExp(`${ext}$`), '');
}
return result;
},
resolve: esmResolver_1.esmResolver,

@@ -44,0 +57,0 @@ });

{
"name": "@poppinss/utils",
"version": "3.2.1",
"version": "3.3.0",
"description": "Handy utilities for repetitive work",

@@ -82,2 +82,3 @@ "main": "build/index.js",

"cuid": "^2.1.8",
"flattie": "^1.1.0",
"fs-readdir-recursive": "^1.1.0",

@@ -91,3 +92,3 @@ "he": "^1.2.0",

"resolve-from": "^5.0.0",
"slugify": "^1.6.0",
"slugify": "^1.6.1",
"truncatise": "0.0.8"

@@ -94,0 +95,0 @@ },

@@ -116,2 +116,3 @@ <div align="center"><img src="https://res.cloudinary.com/adonisjs/image/upload/q_100/v1557762307/poppinss_iftxlt.jpg" width="600px"></div>

- [defineStaticProperty](#definestaticproperty)
- [flatten](#flatten)
- [Helpers](#helpers)

@@ -383,2 +384,44 @@ - [fsReadAll](#fsreadall)

## flatten
Flatten an object/array. The method wraps the [flattie](https://github.com/lukeed/flattie) package.
```ts
import { flatten } from '@poppinss/utils'
flatten({
a: 'hi',
b: {
a: null,
b: ['foo', '', null, 'bar'],
d: 'hello',
e: {
a: 'yo',
b: undefined,
c: 'sup',
d: 0,
f: [
{ foo: 123, bar: 123 },
{ foo: 465, bar: 456 },
]
}
},
c: 'world'
});
// {
// 'a': 'hi',
// 'b.b.0': 'foo',
// 'b.b.1': '',
// 'b.b.3': 'bar',
// 'b.d': 'hello',
// 'b.e.a': 'yo',
// 'b.e.c': 'sup',
// 'b.e.d': 0,
// 'b.e.f.0.foo': 123,
// 'b.e.f.0.bar': 123,
// 'b.e.f.1.foo': 465,
// 'b.e.f.1.bar': 456,
// 'c': 'world'
// }
```
## Helpers

@@ -431,2 +474,12 @@

The method also accepts the following options
```ts
requireAll(join(__dirname, 'config'), recursive, optional, filter)
```
- `recursive` Load all files recursively. Defaults to true.
- `optional` Do not raise exception when the root directory is missing. Defaults to false.
- `filter` Cherry pick files to require. By default, all JavaScript, TypeScript and JSON files are required.
### resolveFrom

@@ -433,0 +486,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc