New:Socket for Asana Is Now Available.Learn more
Get Started

@isoftdata/utility-string

Package Overview
Dependencies
Maintainers
8
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@isoftdata/utility-string

* [pluralIfNeeded](#pluralifneeded) * [stringToBoolean](#stringtoboolean) * [booleanToYesNo](#booleantoyesno)

npmnpm
Version
1.0.3
Version published
Weekly downloads
55
-57.03%
Maintainers
8
Weekly downloads
 
Created
Source

Methods

  • pluralIfNeeded
  • stringToBoolean
  • booleanToYesNo

pluralIfNeeded

API

pluralIfNeeded(number[, pluralSuffix, singleSuffix])

number

Type: number

pluralSuffix

Type: string

Default: 's'

singleSuffix

Type: string

Default: ''(empty string)

Returns

string

Example


//Simple Example
const inventoryList = [ { inventoryId }, { inventoryId } ]

`You have ${inventoryList.length} item${pluralIfNeeded(inventoryList.length)} in inventory` // 'You have 2 items in inventory'

//Example with custom plural suffix and single suffix
const daytonOxenCount = 0
const billOxenCount = 1
const tedOxenCount = 2

`Dayton has ${daytonOxenCount} ox${pluralIfNeeded(daytonOxenCount, 'en', '')}` // 'Dayton has 0 oxen'
`Bill has ${billOxenCount} ox${pluralIfNeeded(billOxenCount, 'en', '')}` // 'Bill has 1 ox'
`Ted has ${tedOxenCount} ox${pluralIfNeeded(tedOxenCount, 'en', '')}` // 'Ted has 2 oxen'

//Another example with custom plural suffix and single suffix
const daytonCactusCount = 0
const billCactusCount = 1
const tedCactusCount = 2

`Dayton has ${daytonCactusCount} cact${pluralIfNeeded(daytonCactusCount, 'i', 'us')}` // 'Dayton has 0 cactus'
`Bill has ${billCactusCount} cact${pluralIfNeeded(billCactusCount, 'i', 'us')}` // 'Bill has 1 cacti'
`Ted has ${tedCactusCount} cact${pluralIfNeeded(tedCactusCount, 'i', 'us')}` // 'Ted has 2 cactus'

stringToBoolean

API

stringToBoolean(string)

string

Type: string

Returns

boolean

Example

const inventoryItem = { inventoryId: 1, usesCost: 'True' }
stringToBoolean(inventoryItem.usesCost) // true

booleanToYesNo

API

booleanToYesNo(boolean)

boolean

Type: boolean

Returns

string

Example

booleanToYesNo(true) // 'Yes'
booleanToYesNo(false) // 'No'

FAQs

Package last updated on 10 Jun 2020

Related posts