#851 Use predictive unique id generation
This commit is contained in:
111
demo/64-complex-numbering-text.ts
Normal file
111
demo/64-complex-numbering-text.ts
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
// Numbered lists - With complex number text
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph, LevelFormat } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
numbering: {
|
||||||
|
config: [
|
||||||
|
{
|
||||||
|
reference: "ref1",
|
||||||
|
levels: [
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
format: LevelFormat.DECIMAL,
|
||||||
|
text: "%1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
level: 1,
|
||||||
|
format: LevelFormat.DECIMAL,
|
||||||
|
text: "%1.%2",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
level: 2,
|
||||||
|
format: LevelFormat.DECIMAL,
|
||||||
|
text: "%1.%2.%3",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "REF1 - lvl:0",
|
||||||
|
numbering: {
|
||||||
|
reference: "ref1",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "REF1 - lvl:1",
|
||||||
|
numbering: {
|
||||||
|
reference: "ref1",
|
||||||
|
level: 1,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "REF1 - lvl:2",
|
||||||
|
numbering: {
|
||||||
|
reference: "ref1",
|
||||||
|
level: 2,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "REF1 - lvl:0",
|
||||||
|
numbering: {
|
||||||
|
reference: "ref1",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "REF1 - lvl:0",
|
||||||
|
numbering: {
|
||||||
|
reference: "ref1",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "REF1 - lvl:0",
|
||||||
|
numbering: {
|
||||||
|
reference: "ref1",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Random text",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "REF1 - inst:1 - lvl:0",
|
||||||
|
numbering: {
|
||||||
|
reference: "ref1",
|
||||||
|
instance: 1,
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "REF1 - inst:0 - lvl:0",
|
||||||
|
numbering: {
|
||||||
|
reference: "ref1",
|
||||||
|
instance: 0,
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "REF1 - inst:0 - lvl:0",
|
||||||
|
numbering: {
|
||||||
|
reference: "ref1",
|
||||||
|
instance: 0,
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
// Used to export the file into a .docx file
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("6-numbering.docx", buffer);
|
||||||
|
});
|
@ -1,6 +1,6 @@
|
|||||||
import { customAlphabet, nanoid } from "nanoid/non-secure";
|
import { nanoid } from "nanoid/non-secure";
|
||||||
|
|
||||||
const numericNanoId = customAlphabet("0123456789", 15);
|
let currentCount = 0;
|
||||||
|
|
||||||
// Twip - twentieths of a point
|
// Twip - twentieths of a point
|
||||||
export const convertMillimetersToTwip = (millimeters: number): number => {
|
export const convertMillimetersToTwip = (millimeters: number): number => {
|
||||||
@ -12,7 +12,7 @@ export const convertInchesToTwip = (inches: number): number => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const uniqueNumericId = (): number => {
|
export const uniqueNumericId = (): number => {
|
||||||
return parseFloat(numericNanoId());
|
return currentCount++;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const uniqueId = (): string => {
|
export const uniqueId = (): string => {
|
||||||
|
Reference in New Issue
Block a user