get-duplicate-name
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

get-duplicate-name

Returns the corresponding name when duplicating an element of a list of elements. The result will be a string with the original name, the string provided to identify a duplicate (e.g. "Copy") and, if duplicates already exist, a number in brackets starting with 2. Example: "Element Copy (4)".

Installation

npm install --save get-duplicate-name

or

yarn add get-duplicate-name

Usage

import getDuplicateName from 'get-duplicate-name'
// or const getDuplicateName = require('get-duplicate-name')

const elements = [
  { name: 'Element' },
  { name: 'Element Copy' },
  { name: 'Element Copy (1)' },
  { name: 'Element Copy (2)' },
  { name: 'Element Copy (3)' },
]
const duplicateString = 'Copy'

const result = getDuplicateName(elements, elements[2].name, duplicateString)
// 'Element Copy (4)'

Readme

Keywords

none

Package Sidebar

Install

npm i get-duplicate-name

Weekly Downloads

3

Version

1.0.1

License

MIT

Unpacked Size

7.43 kB

Total Files

8

Last publish

Collaborators

  • cintaroja
  • roberto-red
  • kanedaki