UNPKG

@carbon/react

Version:

React components for the Carbon Design System

25 lines (21 loc) 784 B
/** * Copyright IBM Corp. 2016, 2023 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; /** Returns an announcement message when the remaining count is low. */ const getAnnouncement = (count, maxCount, singularEntityName = 'character', pluralEntityName = 'characters') => { if (typeof maxCount === 'undefined') return null; const remaining = maxCount - count; if (remaining <= 10 && remaining > 0) { const entityName = remaining === 1 ? singularEntityName : pluralEntityName; return `${remaining} ${entityName} left.`; } if (remaining <= 0) { return `Maximum ${pluralEntityName} reached.`; } return null; }; exports.getAnnouncement = getAnnouncement;