commadus
Version:
Elegantly formats lists with proper punctuation, including support for the Oxford comma.
75 lines (73 loc) • 2.65 kB
JavaScript
/* *******************************************************
* commadus
*
* @license
*
* Apache-2.0
*
* Copyright 2015-2025 Alex Stevovich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @meta
*
* package_name: commadus
* file_name: gen/index.cjs
* purpose: Core functionality and exports combined.
*
* @system
*
* generated_on: 2025-03-15T00:36:08.558Z
* certified_version: 1.0.0
* file_uuid: bba85a1e-47ba-4f04-aba2-d7804cd70ee5
* file_size: 2602 bytes
* file_hash: 06f36e6b2e424c84e032c1af63960f19a6e568033d38db6a73a654ef7ec033c0
* mast_hash: 2904bcf7d0f1c6b1d0bce68051724025c273129343e0700ff81d910e594723e8
* generated_by: preamble on npm!
*
* [Preamble Metadata]
********************************************************/
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var index_exports = {};
__export(index_exports, {
default: () => index_default
});
module.exports = __toCommonJS(index_exports);
function list(items, { oxford = true } = {}) {
if (!Array.isArray(items)) {
throw new TypeError("Expected an array of items.");
}
if (items.length === 0) return "";
if (items.length === 1) return items[0];
if (items.length === 2) return items.join(" and ");
const lastItem = items.pop();
const comma = oxford ? "," : "";
return `${items.join(", ")}${comma} and ${lastItem}`;
}
var index_default = list;