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

@isoftdata/utility-string

Package Overview
Dependencies
Maintainers
13
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@isoftdata/utility-string

latest
npmnpm
Version
2.3.0
Version published
Weekly downloads
104
-41.57%
Maintainers
13
Weekly downloads
 
Created
Source

Node.js CI

Breaking change in version 2: ESM style exports

Functions

  • stringToBoolean
  • booleanToYesNo
  • translate
  • getDuplicateName

stringToBoolean

API

stringToBoolean(string)

string

Type: string

Returns

boolean

Example

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

booleanToYesNo

API

booleanToYesNo(boolean[, translateFn])

Pass the i18next .t function as the optional second argument and 'common:yes' and 'common:no' will be used for the keys passed to the translateFn call.

boolean

Type: boolean

Returns

string

Example

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

translate

Designed to be a drop-in replacement for i18next's .t function that you can use as a default in your translation-aware componments/code as a fallback for consumers that don't have translation/i18next support. It supports the same syntax as i18next's .t function, but does not do translation, just uses the default string you pass. It does support the most common advanced use cases, including interpolation via i18next's iterpolation syntax like {{example}} and {{- example}}.

API

args

(key: string, defaultValue: string, options?: Record<string, string>)

Returns

string

Example

translate('foo', 'blah blah {{foo}} bar', { foo: 'candy' }) // 'blah blah candy bar'
translate('foo', 'what is this?') // 'what is this?'
translate('foo', 'what the {{- curse}} is this?', { curse: 'heck' }) // 'what the heck is this?'

getDuplicateName

Generates a unique numbered name for a duplicate. The strategy (PARENS, SNAKE, or KEBAB) is auto-detected from sourceName when it already carries a numbered suffix, and falls back to the strategy option otherwise. Always uses the next number after the highest found in existingNames.

API

getDuplicateName(sourceName: string, options?: GetDuplicateNameOptions)

sourceName

Type: string

The name to duplicate. If it already ends with a numbered suffix (e.g. foo (1), foo_1, foo-1), the suffix is stripped and the strategy is inferred from it.

options.strategy

Type: 'PARENS' | 'SNAKE' | 'KEBAB' — Default: 'PARENS'

Controls the format of the appended number. Ignored when the strategy is auto-detected from sourceName.

StrategyOutput format
PARENSfoo (2)
SNAKEfoo_2
KEBABfoo-2

options.existingNames

Type: Array<string> — Default: []

Names to check when determining the next number. The result will be one higher than the highest matching number found.

Returns

string

Example

getDuplicateName('Report', { existingNames: ['Report (1)', 'Report (2)'] }) // 'Report (3)'
getDuplicateName('report_2', { existingNames: ['report_1', 'report_2'] }) // 'report_3'
getDuplicateName('Report') // 'Report (1)'

FAQs

Package last updated on 14 Aug 2026

Related posts