Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

citation-js-utils

Package Overview
Dependencies
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

citation-js-utils - npm Package Compare versions

Comparing version 0.0.12 to 0.0.13

20

dist/cjs/index.js

@@ -55,3 +55,3 @@ "use strict";

};
function getInlineCitation(c, kind) {
function getInlineCitation(c, kind, opts) {
var _a, _b, _c;

@@ -65,16 +65,20 @@ const cite = new citation_js_1.default();

const year = (_c = (_b = (_a = data.issued) === null || _a === void 0 ? void 0 : _a['date-parts']) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c[0];
const yearPart = kind === InlineCite.t ? ` (${year})` : `, ${year}`;
const prefix = (opts === null || opts === void 0 ? void 0 : opts.prefix) ? `${opts.prefix} ` : '';
const suffix = (opts === null || opts === void 0 ? void 0 : opts.suffix) ? `, ${opts.suffix}` : '';
const yearPart = kind === InlineCite.t ? ` (${year}${suffix})` : `, ${year}${suffix}`;
if (!authors || authors.length === 0) {
const text = data.publisher || data.title;
return [{ type: 'text', value: `${text}${yearPart}` }];
return [{ type: 'text', value: `${prefix}${text}${yearPart}` }];
}
if (authors.length === 1) {
return [{ type: 'text', value: `${authors[0].family}${yearPart}` }];
return [{ type: 'text', value: `${prefix}${authors[0].family}${yearPart}` }];
}
if (authors.length === 2) {
return [{ type: 'text', value: `${authors[0].family} & ${authors[1].family}${yearPart}` }];
return [
{ type: 'text', value: `${prefix}${authors[0].family} & ${authors[1].family}${yearPart}` },
];
}
if (authors.length > 2) {
return [
{ type: 'text', value: `${authors[0].family} ` },
{ type: 'text', value: `${prefix}${authors[0].family} ` },
{ type: 'emphasis', children: [{ type: 'text', value: 'et al.' }] },

@@ -110,4 +114,4 @@ { type: 'text', value: `${yearPart}` },

{
inline(kind = InlineCite.p) {
return getInlineCitation(c, kind);
inline(kind = InlineCite.p, opts) {
return getInlineCitation(c, kind, opts);
},

@@ -114,0 +118,0 @@ render(style) {

@@ -48,3 +48,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

};
export function getInlineCitation(c, kind) {
export function getInlineCitation(c, kind, opts) {
var _a, _b, _c;

@@ -58,16 +58,20 @@ const cite = new Cite();

const year = (_c = (_b = (_a = data.issued) === null || _a === void 0 ? void 0 : _a['date-parts']) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c[0];
const yearPart = kind === InlineCite.t ? ` (${year})` : `, ${year}`;
const prefix = (opts === null || opts === void 0 ? void 0 : opts.prefix) ? `${opts.prefix} ` : '';
const suffix = (opts === null || opts === void 0 ? void 0 : opts.suffix) ? `, ${opts.suffix}` : '';
const yearPart = kind === InlineCite.t ? ` (${year}${suffix})` : `, ${year}${suffix}`;
if (!authors || authors.length === 0) {
const text = data.publisher || data.title;
return [{ type: 'text', value: `${text}${yearPart}` }];
return [{ type: 'text', value: `${prefix}${text}${yearPart}` }];
}
if (authors.length === 1) {
return [{ type: 'text', value: `${authors[0].family}${yearPart}` }];
return [{ type: 'text', value: `${prefix}${authors[0].family}${yearPart}` }];
}
if (authors.length === 2) {
return [{ type: 'text', value: `${authors[0].family} & ${authors[1].family}${yearPart}` }];
return [
{ type: 'text', value: `${prefix}${authors[0].family} & ${authors[1].family}${yearPart}` },
];
}
if (authors.length > 2) {
return [
{ type: 'text', value: `${authors[0].family} ` },
{ type: 'text', value: `${prefix}${authors[0].family} ` },
{ type: 'emphasis', children: [{ type: 'text', value: 'et al.' }] },

@@ -102,4 +106,4 @@ { type: 'text', value: `${yearPart}` },

{
inline(kind = InlineCite.p) {
return getInlineCitation(c, kind);
inline(kind = InlineCite.p, opts) {
return getInlineCitation(c, kind, opts);
},

@@ -106,0 +110,0 @@ render(style) {

8

dist/types/index.d.ts

@@ -19,3 +19,3 @@ import Cite from 'citation-js';

}
export declare function getInlineCitation(c: Cite, kind: InlineCite): ({
export declare function getInlineCitation(c: Cite, kind: InlineCite, opts?: InlineOptions): ({
type: string;

@@ -32,5 +32,9 @@ value: string;

})[];
export declare type InlineOptions = {
prefix?: string;
suffix?: string;
};
export declare type CitationRenderer = Record<string, {
render: (style?: CitationJSStyles) => string;
inline: (kind?: InlineCite) => InlineNode[];
inline: (kind?: InlineCite, opts?: InlineOptions) => InlineNode[];
getDOI: () => string | undefined;

@@ -37,0 +41,0 @@ cite: any;

{
"name": "citation-js-utils",
"version": "0.0.12",
"version": "0.0.13",
"description": "Utilities for citation-js.",

@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js",

@@ -51,3 +51,3 @@ import type { CitationFormatOptions } from 'citation-js';

export function getInlineCitation(c: Cite, kind: InlineCite) {
export function getInlineCitation(c: Cite, kind: InlineCite, opts?: InlineOptions) {
const cite = new Cite();

@@ -60,18 +60,22 @@ const data = cite.set(c).data[0];

const year = data.issued?.['date-parts']?.[0]?.[0];
const yearPart = kind === InlineCite.t ? ` (${year})` : `, ${year}`;
const prefix = opts?.prefix ? `${opts.prefix} ` : '';
const suffix = opts?.suffix ? `, ${opts.suffix}` : '';
const yearPart = kind === InlineCite.t ? ` (${year}${suffix})` : `, ${year}${suffix}`;
if (!authors || authors.length === 0) {
const text = data.publisher || data.title;
return [{ type: 'text', value: `${text}${yearPart}` }];
return [{ type: 'text', value: `${prefix}${text}${yearPart}` }];
}
if (authors.length === 1) {
return [{ type: 'text', value: `${authors[0].family}${yearPart}` }];
return [{ type: 'text', value: `${prefix}${authors[0].family}${yearPart}` }];
}
if (authors.length === 2) {
return [{ type: 'text', value: `${authors[0].family} & ${authors[1].family}${yearPart}` }];
return [
{ type: 'text', value: `${prefix}${authors[0].family} & ${authors[1].family}${yearPart}` },
];
}
if (authors.length > 2) {
return [
{ type: 'text', value: `${authors[0].family} ` },
{ type: 'text', value: `${prefix}${authors[0].family} ` },
{ type: 'emphasis', children: [{ type: 'text', value: 'et al.' }] },

@@ -84,2 +88,4 @@ { type: 'text', value: `${yearPart}` },

export type InlineOptions = { prefix?: string; suffix?: string };
export type CitationRenderer = Record<

@@ -89,3 +95,3 @@ string,

render: (style?: CitationJSStyles) => string;
inline: (kind?: InlineCite) => InlineNode[];
inline: (kind?: InlineCite, opts?: InlineOptions) => InlineNode[];
getDOI: () => string | undefined;

@@ -121,4 +127,4 @@ cite: any;

{
inline(kind = InlineCite.p) {
return getInlineCitation(c, kind);
inline(kind = InlineCite.p, opts) {
return getInlineCitation(c, kind, opts);
},

@@ -125,0 +131,0 @@ render(style?: CitationJSStyles) {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc