Socket
Socket
Sign inDemoInstall

@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.1.1 to 3.1.2

2

LICENSE.md
# The MIT License
Copyright 2020 Harminder virk, contributors
Copyright 2021 Harminder Virk, contributors

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

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

@@ -35,18 +35,18 @@ "main": "build/index.js",

"devDependencies": {
"@adonisjs/mrm-preset": "^3.0.0",
"@adonisjs/require-ts": "^2.0.3",
"@poppinss/dev-utils": "^1.1.1",
"@adonisjs/mrm-preset": "^3.1.0",
"@adonisjs/require-ts": "^2.0.4",
"@poppinss/dev-utils": "^1.1.2",
"@types/fs-readdir-recursive": "^1.0.0",
"@types/lodash": "^4.14.168",
"@types/lodash": "^4.14.169",
"@types/ms": "^0.7.31",
"@types/node": "^15.0.1",
"@types/node": "^15.3.0",
"@types/pluralize": "0.0.29",
"@types/require-all": "^3.0.1",
"commitizen": "^4.2.3",
"@types/require-all": "^3.0.2",
"commitizen": "^4.2.4",
"cz-conventional-changelog": "^3.3.0",
"del-cli": "^3.0.1",
"doctoc": "^2.0.0",
"eslint": "^7.25.0",
"eslint": "^7.26.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-adonis": "^1.3.0",
"eslint-plugin-adonis": "^1.3.1",
"eslint-plugin-prettier": "^3.4.0",

@@ -58,3 +58,3 @@ "github-label-sync": "^2.0.0",

"np": "^7.5.0",
"prettier": "^2.2.1",
"prettier": "^2.3.0",
"typescript": "^4.2.4"

@@ -101,3 +101,3 @@ },

"resolve-from": "^5.0.0",
"slugify": "^1.5.1",
"slugify": "^1.5.3",
"truncatise": "0.0.8"

@@ -104,0 +104,0 @@ },

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

[![circleci-image]][circleci-url] [![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url] [![synk-image]][synk-url]
[![gh-workflow-image]][gh-workflow-url] [![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url] [![synk-image]][synk-url]

@@ -51,11 +51,11 @@ This module exports a collection of re-usable utilties to avoid re-writing the same code in every other package. We also include a handful of Lodash utilities, which are used across the AdonisJS packages eco-system.

import {
MessageBuilder,
base64,
compose,
fsReadAll,
interpolate,
requireAll,
resolveDir,
resolveFrom,
safeEqual
MessageBuilder,
base64,
compose,
fsReadAll,
interpolate,
requireAll,
resolveDir,
resolveFrom,
safeEqual
} from '@poppinss/utils/build/helpers'

@@ -107,2 +107,3 @@

<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
## Table of contents

@@ -386,2 +387,3 @@

## Helpers
The helpers module is also available in AdonisJS applications as follows:

@@ -475,7 +477,7 @@

interpolate('hello {{ username }}', {
username: 'virk'
username: 'virk',
})
interpolate('hello {{ users.0.username }}', {
users: [{ username: 'virk' }]
users: [{ username: 'virk' }],
})

@@ -492,3 +494,3 @@ ```

interpolate('\\{{ username }} expression evaluates to {{ username }}', {
username: 'virk'
username: 'virk',
})

@@ -644,5 +646,7 @@ // Output: {{ username }} expression evaluates to virk

### string
The `string` module includes a bunch of helper methods to work with strings.
The `string` module includes a bunch of helper methods to work with strings.
#### camelCase
Convert a string to its `camelCase` version.

@@ -657,2 +661,3 @@

#### snakeCase
Convert a string to its `snake_case` version.

@@ -667,2 +672,3 @@

#### dashCase
Convert a string to its `dash-case` version. Optionally, you can also capitalize the first letter of each segment.

@@ -678,4 +684,5 @@

#### pascalCase
Convert a string to its `PascalCase` version.
Convert a string to its `PascalCase` version.
```ts

@@ -688,2 +695,3 @@ import { string } from '@poppinss/utils/build/helpers'

#### capitalCase
Capitalize a string

@@ -698,2 +706,3 @@

#### sentenceCase
Convert string to a sentence

@@ -708,2 +717,3 @@

#### dotCase
Convert string to its `dot.case` version.

@@ -718,2 +728,3 @@

#### noCase
Remove all sorts of casing

@@ -730,2 +741,3 @@

#### titleCase
Convert a sentence to title case

@@ -740,2 +752,3 @@

#### pluralize
Pluralize a word.

@@ -772,2 +785,3 @@

#### truncate
Truncate a string after a given number of characters

@@ -778,6 +792,3 @@

string.truncate(
'This is a very long, maybe not that long title',
12
) // This is a ve...
string.truncate('This is a very long, maybe not that long title', 12) // This is a ve...
```

@@ -788,9 +799,5 @@

```ts
string.truncate(
'This is a very long, maybe not that long title',
12,
{
completeWords: true
}
) // This is a very...
string.truncate('This is a very long, maybe not that long title', 12, {
completeWords: true,
}) // This is a very...
```

@@ -801,13 +808,10 @@

```ts
string.truncate(
'This is a very long, maybe not that long title',
12,
{
completeWords: true,
suffix: ' <a href="/1"> Read more </a>',
}
) // This is a very <a href="/1"> Read more </a>
string.truncate('This is a very long, maybe not that long title', 12, {
completeWords: true,
suffix: ' <a href="/1"> Read more </a>',
}) // This is a very <a href="/1"> Read more </a>
```
#### excerpt
The `excerpt` method is same as the `truncate` method. However, it strips the HTML from the string.

@@ -818,9 +822,7 @@

string.excerpt(
'<p>This is a <strong>very long</strong>, maybe not that long title</p>',
12
) // This is a very...
string.excerpt('<p>This is a <strong>very long</strong>, maybe not that long title</p>', 12) // This is a very...
```
#### condenseWhitespace
Condense whitespaces from a given string. The method removes the whitespace from the `left`, `right` and multiple whitespace in between the words.

@@ -836,2 +838,3 @@

#### escapeHTML
Escape HTML from the string

@@ -851,8 +854,5 @@

string.escapeHTML(
'<p> foo © bar </p>',
{
encodeSymbols: true
}
)
string.escapeHTML('<p> foo © bar </p>', {
encodeSymbols: true,
})
// &lt;p&gt; foo &#xA9; bar &lt;/p&gt;

@@ -862,2 +862,3 @@ ```

#### encodeSymbols
Encode symbols. Checkout [he](https://npm.im/he) for available options

@@ -873,17 +874,11 @@

#### toSentence
Join an array of words with a separator.
Join an array of words with a separator.
```ts
import { string } from '@poppinss/utils/build/helpers'
string.toSentence([
'route',
'middleware',
'controller'
]) // route, middleware, and controller
string.toSentence(['route', 'middleware', 'controller']) // route, middleware, and controller
string.toSentence([
'route',
'middleware'
]) // route and middleware
string.toSentence(['route', 'middleware']) // route and middleware
```

@@ -898,9 +893,5 @@

```ts
string.toSentence([
'route',
'middleware',
'controller'
], {
string.toSentence(['route', 'middleware', 'controller'], {
separator: '/ ',
lastSeparator: '/or '
lastSeparator: '/or ',
}) // route/ middleware/or controller

@@ -910,2 +901,3 @@ ```

#### prettyBytes
Convert bytes value to a human readable string. For options, recommend the [bytes](https://www.npmjs.com/package/bytes) package.

@@ -921,2 +913,3 @@

#### toBytes
Convert human readable string to bytes. This method is the opposite of the `prettyBytes` method.

@@ -931,2 +924,3 @@

#### prettyMs
Convert time in milliseconds to a human readable string

@@ -942,2 +936,3 @@

#### toMs
Convert human readable string to milliseconds. This method is the opposite of the `prettyMs` method.

@@ -952,2 +947,3 @@

#### ordinalize
Ordinalize a string or a number value

@@ -963,2 +959,3 @@

#### generateRandom
Generate a cryptographically strong random string

@@ -973,2 +970,3 @@

#### isEmpty
Find if a value is empty. Also checks for empty strings with all whitespace

@@ -984,8 +982,9 @@

### Types
The types module allows distinguishing between different Javascript datatypes. The `typeof` returns the same type for many different values. For example:
```ts
typeof ({}) // object
typeof ([]) // object
typeof (null) // object
typeof {} // object
typeof [] // object
typeof null // object
```

@@ -996,2 +995,3 @@

#### lookup
Returns a more accurate type for a given value.

@@ -1012,2 +1012,3 @@

#### isNull
Find if the given value is null

@@ -1022,2 +1023,3 @@

#### isBoolean
Find if the given value is a boolean

@@ -1032,2 +1034,3 @@

#### isBuffer
Find if the given value is a buffer

@@ -1042,2 +1045,3 @@

#### isNumber
Find if the given value is a number

@@ -1052,2 +1056,3 @@

#### isString
Find if the given value is a string

@@ -1062,2 +1067,3 @@

#### isArguments
Find if the given value is an arguments object

@@ -1074,2 +1080,3 @@

#### isObject
Find if the given value is a plain object

@@ -1084,2 +1091,3 @@

#### isDate
Find if the given value is a date object

@@ -1094,2 +1102,3 @@

#### isArray
Find if the given value is an array

@@ -1104,2 +1113,3 @@

#### isRegexp
Find if the given value is an regular expression

@@ -1114,2 +1124,3 @@

#### isError
Find if the given value is an instance of the error object

@@ -1126,2 +1137,3 @@

#### isFunction
Find if the given value is a function

@@ -1136,2 +1148,3 @@

#### isClass
Find if the given value is a class constructor. Uses regex to distinguish between a function and a class.

@@ -1149,2 +1162,3 @@

#### isInteger
Find if the given value is an integer.

@@ -1155,13 +1169,14 @@

types.isInteger(22.00) // true
types.isInteger(22.0) // true
types.isInteger(22) // true
types.isInteger(-1) // true
types.isInteger(-1.00) // true
types.isInteger(-1.0) // true
types.isInteger(22.10) // false
types.isInteger(.3) // false
types.isInteger(-.3) // false
types.isInteger(22.1) // false
types.isInteger(0.3) // false
types.isInteger(-0.3) // false
```
#### isFloat
Find if the given value is an float number.

@@ -1172,9 +1187,9 @@

types.isFloat(22.10) // true
types.isFloat(-22.10) // true
types.isFloat(.3) // true
types.isFloat(-.3) // true
types.isFloat(22.1) // true
types.isFloat(-22.1) // true
types.isFloat(0.3) // true
types.isFloat(-0.3) // true
types.isFloat(22.00) // false
types.isFloat(-22.00) // false
types.isFloat(22.0) // false
types.isFloat(-22.0) // false
types.isFloat(-22) // false

@@ -1184,2 +1199,3 @@ ```

#### isDecimal
Find if the given value has a decimal. The value can be a string or a number. The number values are casted to a string by calling the `toString()` method on the value itself.

@@ -1218,2 +1234,3 @@

### ObjectBuilder
A very simple class to conditionally builder an object. Quite often, I create a new object from an existing one and wants to avoid writing undefined values to it. For example

@@ -1239,4 +1256,3 @@

.add('id', user.id)
.add('createdAt', user.createdAt && user.createdAt.toString())
.value // returns the underlying object
.add('createdAt', user.createdAt && user.createdAt.toString()).value // returns the underlying object
```

@@ -1250,11 +1266,15 @@

[circleci-image]: https://img.shields.io/circleci/project/github/poppinss/utils/master.svg?style=for-the-badge&logo=circleci
[circleci-url]: https://circleci.com/gh/poppinss/utils 'circleci'
[gh-workflow-image]: https://img.shields.io/github/workflow/status/poppinss/utils/test?style=for-the-badge
[gh-workflow-url]: https://github.com/poppinss/utils/actions/workflows/test.yml "Github action"
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
[typescript-url]: "typescript"
[npm-image]: https://img.shields.io/npm/v/@poppinss/utils.svg?style=for-the-badge&logo=npm
[npm-url]: https://npmjs.org/package/@poppinss/utils 'npm'
[license-image]: https://img.shields.io/npm/l/@poppinss/utils?color=blueviolet&style=for-the-badge
[license-url]: LICENSE.md 'license'
[synk-image]: https://img.shields.io/snyk/vulnerabilities/github/poppinss/utils?label=Synk%20Vulnerabilities&style=for-the-badge
[synk-url]: https://snyk.io/test/github/poppinss/utils?targetFile=package.json 'synk'
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