Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
@poppinss/utils
Advanced tools
@poppinss/utils is a utility library that provides a collection of helper functions for various common tasks in JavaScript and TypeScript. It includes utilities for data manipulation, type checking, and more.
String Manipulation
The string manipulation utilities include functions like camelCase, which converts a string to camel case.
const { string } = require('@poppinss/utils');
const camelCaseString = string.camelCase('hello world');
console.log(camelCaseString); // 'helloWorld'
Object Utilities
Object utilities include functions like clone, which creates a deep copy of an object.
const { object } = require('@poppinss/utils');
const obj = { a: 1, b: 2 };
const clonedObj = object.clone(obj);
console.log(clonedObj); // { a: 1, b: 2 }
Type Checking
Type checking utilities include functions like is.number and is.string, which check the type of a given value.
const { is } = require('@poppinss/utils');
console.log(is.number(123)); // true
console.log(is.string(123)); // false
Lodash is a popular utility library that provides a wide range of functions for data manipulation, type checking, and more. It is more comprehensive and widely used compared to @poppinss/utils.
Underscore is another utility library similar to Lodash, offering a variety of functions for common programming tasks. It is older and less feature-rich than Lodash but still widely used.
Ramda is a functional programming library for JavaScript that provides utility functions with a focus on immutability and pure functions. It offers a different approach compared to @poppinss/utils, emphasizing functional programming paradigms.
This module exports a collection of re-usable utilties to avoid re-writing the same code in every other package. Do make sure to check the API docs as well.
Install the package from npm as follows:
npm i @poppinss/utils
# yarn
yarn add @poppinss/utils
and then use it as follows
import { Exception, requireAll, esmRequire } from '@poppinss/utils'
The module exports the following methods/classes.
Raise an exception with custom status code and error code.
import { Exception } from '@poppinss/utils'
new Exception('Route not found', 404, 'E_ROUTE_NOT_FOUND')
Require a module and returns the default
export if module is an esModule
or returns the actual value in case of CommonJs.
The method is helpful when you don't know that you are requiring a CommonJs module or a ESM module.
TS module (user.ts)
export default {
username: 'foo'
}
import { esmRequire } from '@poppinss/utils'
esmRequire('./user') // returns { username: 'foo' }
Require all .js
and .json
and .ts
files from a given directory.
import { join } from 'path'
import { requireAll } from '@poppinss/utils'
requireAll(join(__dirname, 'config'))
// Disable recursive
requireAll(join(__dirname, 'config'), false)
// Ignore error when directory is missing
requireAll(join(__dirname, 'config'), true, true)
Resolves a module from a given location. It is like require.resolve
but handles couple of extra
edge cases.
require.resolve
raises an exception.require.resolve
bug, defined in this issue.Following are the autogenerated files via Typedoc
FAQs
Handy utilities for repetitive work
The npm package @poppinss/utils receives a total of 120,310 weekly downloads. As such, @poppinss/utils popularity was classified as popular.
We found that @poppinss/utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.