1.0.1 • Published 10 months ago

get-duplicate-name v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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)'
1.0.1

10 months ago

1.0.0

10 months ago