@promptbook/utils 0.60.1 → 0.61.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -19
- package/esm/index.es.js +391 -273
- package/esm/index.es.js.map +1 -1
- package/esm/typings/promptbook-collection/index.d.ts +61 -4
- package/esm/typings/src/_packages/core.index.d.ts +8 -8
- package/esm/typings/src/_packages/markdown-utils.d.ts +17 -0
- package/esm/typings/src/_packages/types.index.d.ts +11 -6
- package/esm/typings/src/_packages/utils.index.d.ts +23 -19
- package/esm/typings/src/cli/cli-commands/hello.d.ts +7 -0
- package/esm/typings/src/cli/cli-commands/make.d.ts +7 -0
- package/esm/typings/src/cli/cli-commands/prettify.d.ts +7 -0
- package/esm/typings/src/collection/collectionToJson.d.ts +3 -0
- package/esm/typings/src/collection/collectionToJson.test.d.ts +6 -0
- package/esm/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +2 -1
- package/esm/typings/src/commands/BLOCK/BlockCommand.d.ts +11 -0
- package/esm/typings/src/commands/BLOCK/BlockTypes.d.ts +13 -0
- package/esm/typings/src/commands/BLOCK/blockCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/EXPECT/ExpectAmountCommand.d.ts +14 -0
- package/esm/typings/src/commands/EXPECT/ExpectCommand.d.ts +9 -0
- package/esm/typings/src/commands/EXPECT/ExpectFormatCommand.d.ts +7 -0
- package/esm/typings/src/commands/EXPECT/expectCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/JOKER/JokerCommand.d.ts +11 -0
- package/esm/typings/src/commands/JOKER/jokerCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +12 -0
- package/esm/typings/src/commands/KNOWLEDGE/knowledgeCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/MODEL/ModelCommand.d.ts +13 -0
- package/esm/typings/src/commands/MODEL/modelCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/PARAMETER/ParameterCommand.d.ts +15 -0
- package/esm/typings/src/commands/PARAMETER/parameterCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/PERSONA/PersonaCommand.d.ts +11 -0
- package/esm/typings/src/commands/PERSONA/personaCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/POSTPROCESS/PostprocessCommand.d.ts +11 -0
- package/esm/typings/src/commands/POSTPROCESS/postprocessCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/PROMPTBOOK_VERSION/PromptbookVersionCommand.d.ts +11 -0
- package/esm/typings/src/commands/PROMPTBOOK_VERSION/promptbookVersionCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/URL/UrlCommand.d.ts +10 -0
- package/esm/typings/src/commands/URL/urlCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/X_ACTION/ActionCommand.d.ts +9 -0
- package/esm/typings/src/commands/X_ACTION/actionCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/X_ACTION/actionCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/X_INSTRUMENT/InstrumentCommand.d.ts +9 -0
- package/esm/typings/src/commands/X_INSTRUMENT/instrumentCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/X_INSTRUMENT/instrumentCommandParser.d.ts +9 -0
- package/esm/typings/src/commands/_BOILERPLATE/BoilerplateCommand.d.ts +10 -0
- package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +12 -0
- package/esm/typings/src/commands/_common/parseCommand.d.ts +12 -0
- package/esm/typings/src/commands/_common/parseCommand.test.d.ts +1 -0
- package/esm/typings/src/commands/_common/types/Command.d.ts +6 -0
- package/esm/typings/src/commands/_common/types/CommandParser.d.ts +36 -0
- package/esm/typings/src/commands/_common/types/CommandUsagePlaces.d.ts +9 -0
- package/esm/typings/src/commands/index.d.ts +4 -0
- package/esm/typings/src/config.d.ts +4 -0
- package/esm/typings/src/conversion/pipelineJsonToString.d.ts +2 -0
- package/esm/typings/src/conversion/pipelineStringToJson.d.ts +2 -3
- package/esm/typings/src/conversion/pipelineStringToJsonSync.d.ts +4 -2
- package/esm/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts +2 -2
- package/esm/typings/src/conversion/utils/extractVariables.d.ts +1 -1
- package/esm/typings/src/conversion/validation/validatePipeline-logicErrors.test.d.ts +3 -0
- package/esm/typings/src/errors/NotYetImplementedError.d.ts +7 -0
- package/esm/typings/src/errors/{SyntaxError.d.ts → ParsingError.d.ts} +2 -2
- package/{umd/typings/src/errors/ExecutionError.d.ts → esm/typings/src/errors/PipelineExecutionError.d.ts} +2 -2
- package/esm/typings/src/errors/_ExpectError.d.ts +2 -2
- package/esm/typings/src/execution/ExecutionTools.d.ts +4 -3
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +24 -5
- package/esm/typings/src/execution/PromptResult.d.ts +2 -2
- package/esm/typings/src/execution/assertsExecutionSuccessful.d.ts +1 -1
- package/esm/typings/src/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +1 -1
- package/esm/typings/src/execution/utils/checkExpectations.d.ts +1 -1
- package/esm/typings/src/execution/utils/replaceParameters.d.ts +1 -1
- package/esm/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +5 -0
- package/esm/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +5 -5
- package/esm/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -0
- package/esm/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +5 -0
- package/esm/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +5 -0
- package/esm/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +5 -0
- package/esm/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +10 -0
- package/esm/typings/src/llm-providers/mocked/fakeTextToExpectations.d.ts +1 -1
- package/esm/typings/src/llm-providers/mocked/test/fakeTextToExpectations.test.d.ts +1 -0
- package/esm/typings/src/llm-providers/mocked/test/faked-completion.test.d.ts +1 -0
- package/esm/typings/src/llm-providers/mocked/test/mocked-chat.test.d.ts +5 -0
- package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +14 -1
- package/esm/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +16 -0
- package/esm/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +6 -1
- package/esm/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +1 -1
- package/esm/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
- package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +13 -3
- package/esm/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
- package/esm/typings/src/personas/personaToModelRequirements.d.ts +6 -0
- package/esm/typings/src/scripting/javascript/utils/preserve.d.ts +2 -1
- package/esm/typings/src/types/Arrayable.d.ts +10 -0
- package/esm/typings/src/types/PipelineJson/Expectations.d.ts +28 -0
- package/esm/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +16 -0
- package/esm/typings/src/types/PipelineJson/PipelineJson.d.ts +8 -2
- package/esm/typings/src/types/PipelineJson/PromptDialogJson.d.ts +7 -0
- package/esm/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +6 -142
- package/esm/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +77 -0
- package/esm/typings/src/types/PipelineJson/ScriptJson.d.ts +14 -0
- package/esm/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +7 -0
- package/esm/typings/src/types/Prompt.d.ts +3 -3
- package/esm/typings/src/types/TaskProgress.d.ts +2 -2
- package/esm/typings/src/types/execution-report/ExecutionReportJson.d.ts +3 -3
- package/esm/typings/src/types/typeAliases.d.ts +50 -6
- package/esm/typings/src/utils/arrayableToArray.d.ts +11 -0
- package/esm/typings/src/utils/arrayableToArray.test.d.ts +1 -0
- package/esm/typings/src/utils/emojis.d.ts +1 -0
- package/esm/typings/src/utils/expectation-counters/countCharacters.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countLines.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countPages.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countParagraphs.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countSentences.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/countWords.d.ts +1 -1
- package/esm/typings/src/utils/expectation-counters/index.d.ts +2 -2
- package/esm/typings/src/utils/markdown/flattenMarkdown.d.ts +14 -0
- package/esm/typings/src/utils/markdown/flattenMarkdown.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/parseMarkdownSection.d.ts +30 -0
- package/esm/typings/src/utils/markdown/parseMarkdownSection.test.d.ts +1 -0
- package/esm/typings/src/utils/markdown/prettifyMarkdown.d.ts +1 -0
- package/esm/typings/src/utils/markdown/splitMarkdownIntoSections.d.ts +12 -0
- package/esm/typings/src/utils/markdown/splitMarkdownIntoSections.test.d.ts +1 -0
- package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +8 -1
- package/esm/typings/src/utils/normalization/normalizeTo_PascalCase.d.ts +8 -1
- package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +13 -1
- package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +8 -1
- package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +8 -1
- package/esm/typings/src/{conversion/utils → utils}/parseNumber.d.ts +1 -1
- package/esm/typings/src/utils/parseNumber.test.d.ts +1 -0
- package/esm/typings/src/utils/sets/difference.d.ts +2 -0
- package/esm/typings/src/utils/sets/intersection.d.ts +2 -0
- package/esm/typings/src/utils/sets/union.d.ts +2 -0
- package/esm/typings/src/utils/validators/email/isValidEmail.d.ts +5 -0
- package/esm/typings/src/utils/validators/email/isValidEmail.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/filePath/isValidFilePath.d.ts +7 -0
- package/esm/typings/src/utils/validators/filePath/isValidFilePath.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +2 -0
- package/esm/typings/src/utils/validators/javascriptName/isValidJavascriptName.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +12 -0
- package/esm/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +9 -0
- package/esm/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.d.ts +9 -0
- package/esm/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/url/isUrlOnPrivateNetwork.d.ts +12 -0
- package/esm/typings/src/utils/validators/url/isUrlOnPrivateNetwork.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +12 -0
- package/esm/typings/src/utils/validators/url/isValidPipelineUrl.test.d.ts +1 -0
- package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +3 -0
- package/esm/typings/src/utils/validators/uuid/isValidUuid.d.ts +5 -0
- package/esm/typings/src/utils/validators/uuid/isValidUuid.test.d.ts +1 -0
- package/esm/typings/src/version.d.ts +3 -2
- package/package.json +1 -1
- package/umd/index.umd.js +399 -277
- package/umd/index.umd.js.map +1 -1
- package/umd/typings/promptbook-collection/index.d.ts +61 -4
- package/umd/typings/src/_packages/core.index.d.ts +8 -8
- package/umd/typings/src/_packages/markdown-utils.d.ts +17 -0
- package/umd/typings/src/_packages/types.index.d.ts +11 -6
- package/umd/typings/src/_packages/utils.index.d.ts +23 -19
- package/umd/typings/src/cli/cli-commands/hello.d.ts +7 -0
- package/umd/typings/src/cli/cli-commands/make.d.ts +7 -0
- package/umd/typings/src/cli/cli-commands/prettify.d.ts +7 -0
- package/umd/typings/src/collection/collectionToJson.d.ts +3 -0
- package/umd/typings/src/collection/collectionToJson.test.d.ts +6 -0
- package/umd/typings/src/collection/constructors/createCollectionFromDirectory.d.ts +2 -1
- package/umd/typings/src/commands/BLOCK/BlockCommand.d.ts +11 -0
- package/umd/typings/src/commands/BLOCK/BlockTypes.d.ts +13 -0
- package/umd/typings/src/commands/BLOCK/blockCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/BLOCK/blockCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/EXPECT/ExpectAmountCommand.d.ts +14 -0
- package/umd/typings/src/commands/EXPECT/ExpectCommand.d.ts +9 -0
- package/umd/typings/src/commands/EXPECT/ExpectFormatCommand.d.ts +7 -0
- package/umd/typings/src/commands/EXPECT/expectCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/EXPECT/expectCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/JOKER/JokerCommand.d.ts +11 -0
- package/umd/typings/src/commands/JOKER/jokerCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/JOKER/jokerCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/KNOWLEDGE/KnowledgeCommand.d.ts +12 -0
- package/umd/typings/src/commands/KNOWLEDGE/knowledgeCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/KNOWLEDGE/knowledgeCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/MODEL/ModelCommand.d.ts +13 -0
- package/umd/typings/src/commands/MODEL/modelCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/MODEL/modelCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/PARAMETER/ParameterCommand.d.ts +15 -0
- package/umd/typings/src/commands/PARAMETER/parameterCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/PARAMETER/parameterCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/PERSONA/PersonaCommand.d.ts +11 -0
- package/umd/typings/src/commands/PERSONA/personaCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/PERSONA/personaCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/POSTPROCESS/PostprocessCommand.d.ts +11 -0
- package/umd/typings/src/commands/POSTPROCESS/postprocessCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/POSTPROCESS/postprocessCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/PROMPTBOOK_VERSION/PromptbookVersionCommand.d.ts +11 -0
- package/umd/typings/src/commands/PROMPTBOOK_VERSION/promptbookVersionCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/PROMPTBOOK_VERSION/promptbookVersionCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/URL/UrlCommand.d.ts +10 -0
- package/umd/typings/src/commands/URL/urlCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/URL/urlCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/X_ACTION/ActionCommand.d.ts +9 -0
- package/umd/typings/src/commands/X_ACTION/actionCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/X_ACTION/actionCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/X_INSTRUMENT/InstrumentCommand.d.ts +9 -0
- package/umd/typings/src/commands/X_INSTRUMENT/instrumentCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/X_INSTRUMENT/instrumentCommandParser.d.ts +9 -0
- package/umd/typings/src/commands/_BOILERPLATE/BoilerplateCommand.d.ts +10 -0
- package/umd/typings/src/commands/_BOILERPLATE/boilerplateCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/_BOILERPLATE/boilerplateCommandParser.d.ts +12 -0
- package/umd/typings/src/commands/_common/parseCommand.d.ts +12 -0
- package/umd/typings/src/commands/_common/parseCommand.test.d.ts +1 -0
- package/umd/typings/src/commands/_common/types/Command.d.ts +6 -0
- package/umd/typings/src/commands/_common/types/CommandParser.d.ts +36 -0
- package/umd/typings/src/commands/_common/types/CommandUsagePlaces.d.ts +9 -0
- package/umd/typings/src/commands/index.d.ts +4 -0
- package/umd/typings/src/config.d.ts +4 -0
- package/umd/typings/src/conversion/pipelineJsonToString.d.ts +2 -0
- package/umd/typings/src/conversion/pipelineStringToJson.d.ts +2 -3
- package/umd/typings/src/conversion/pipelineStringToJsonSync.d.ts +4 -2
- package/umd/typings/src/conversion/utils/extractParametersFromPromptTemplate.d.ts +2 -2
- package/umd/typings/src/conversion/utils/extractVariables.d.ts +1 -1
- package/umd/typings/src/conversion/validation/validatePipeline-logicErrors.test.d.ts +3 -0
- package/umd/typings/src/errors/NotYetImplementedError.d.ts +7 -0
- package/umd/typings/src/errors/{SyntaxError.d.ts → ParsingError.d.ts} +2 -2
- package/{esm/typings/src/errors/ExecutionError.d.ts → umd/typings/src/errors/PipelineExecutionError.d.ts} +2 -2
- package/umd/typings/src/errors/_ExpectError.d.ts +2 -2
- package/umd/typings/src/execution/ExecutionTools.d.ts +4 -3
- package/umd/typings/src/execution/LlmExecutionTools.d.ts +24 -5
- package/umd/typings/src/execution/PromptResult.d.ts +2 -2
- package/umd/typings/src/execution/assertsExecutionSuccessful.d.ts +1 -1
- package/umd/typings/src/execution/translation/automatic-translate/automatic-translators/utils/extractMultiplicatedOccurrence.d.ts +1 -1
- package/umd/typings/src/execution/utils/checkExpectations.d.ts +1 -1
- package/umd/typings/src/execution/utils/replaceParameters.d.ts +1 -1
- package/umd/typings/src/knowledge/prepare-knowledge/markdown/prepareKnowledgeFromMarkdown.d.ts +5 -0
- package/umd/typings/src/llm-providers/anthropic-claude/AnthropicClaudeExecutionTools.d.ts +5 -5
- package/umd/typings/src/llm-providers/anthropic-claude/anthropic-claude-models.d.ts +1 -0
- package/umd/typings/src/llm-providers/azure-openai/AzureOpenAiExecutionTools.d.ts +5 -0
- package/umd/typings/src/llm-providers/langtail/LangtailExecutionTools.d.ts +5 -0
- package/umd/typings/src/llm-providers/mocked/MockedEchoLlmExecutionTools.d.ts +5 -0
- package/umd/typings/src/llm-providers/mocked/MockedFackedLlmExecutionTools.d.ts +10 -0
- package/umd/typings/src/llm-providers/mocked/fakeTextToExpectations.d.ts +1 -1
- package/umd/typings/src/llm-providers/mocked/test/fakeTextToExpectations.test.d.ts +1 -0
- package/umd/typings/src/llm-providers/mocked/test/faked-completion.test.d.ts +1 -0
- package/umd/typings/src/llm-providers/mocked/test/mocked-chat.test.d.ts +5 -0
- package/umd/typings/src/llm-providers/multiple/MultipleLlmExecutionTools.d.ts +14 -1
- package/umd/typings/src/llm-providers/multiple/joinLlmExecutionTools.d.ts +16 -0
- package/umd/typings/src/llm-providers/openai/OpenAiExecutionTools.d.ts +6 -1
- package/umd/typings/src/llm-providers/openai/computeOpenaiUsage.d.ts +1 -1
- package/umd/typings/src/llm-providers/openai/openai-models.d.ts +1 -0
- package/umd/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +13 -3
- package/umd/typings/src/llm-providers/remote/startRemoteServer.d.ts +1 -0
- package/umd/typings/src/personas/personaToModelRequirements.d.ts +6 -0
- package/umd/typings/src/scripting/javascript/utils/preserve.d.ts +2 -1
- package/umd/typings/src/types/Arrayable.d.ts +10 -0
- package/umd/typings/src/types/PipelineJson/Expectations.d.ts +28 -0
- package/umd/typings/src/types/PipelineJson/LlmTemplateJson.d.ts +16 -0
- package/umd/typings/src/types/PipelineJson/PipelineJson.d.ts +8 -2
- package/umd/typings/src/types/PipelineJson/PromptDialogJson.d.ts +7 -0
- package/umd/typings/src/types/PipelineJson/PromptTemplateJson.d.ts +6 -142
- package/umd/typings/src/types/PipelineJson/PromptTemplateJsonCommon.d.ts +77 -0
- package/umd/typings/src/types/PipelineJson/ScriptJson.d.ts +14 -0
- package/umd/typings/src/types/PipelineJson/SimpleTemplateJson.d.ts +7 -0
- package/umd/typings/src/types/Prompt.d.ts +3 -3
- package/umd/typings/src/types/TaskProgress.d.ts +2 -2
- package/umd/typings/src/types/execution-report/ExecutionReportJson.d.ts +3 -3
- package/umd/typings/src/types/typeAliases.d.ts +50 -6
- package/umd/typings/src/utils/arrayableToArray.d.ts +11 -0
- package/umd/typings/src/utils/arrayableToArray.test.d.ts +1 -0
- package/umd/typings/src/utils/emojis.d.ts +1 -0
- package/umd/typings/src/utils/expectation-counters/countCharacters.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/countLines.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/countPages.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/countParagraphs.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/countSentences.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/countWords.d.ts +1 -1
- package/umd/typings/src/utils/expectation-counters/index.d.ts +2 -2
- package/umd/typings/src/utils/markdown/flattenMarkdown.d.ts +14 -0
- package/umd/typings/src/utils/markdown/flattenMarkdown.test.d.ts +1 -0
- package/umd/typings/src/utils/markdown/parseMarkdownSection.d.ts +30 -0
- package/umd/typings/src/utils/markdown/parseMarkdownSection.test.d.ts +1 -0
- package/umd/typings/src/utils/markdown/prettifyMarkdown.d.ts +1 -0
- package/umd/typings/src/utils/markdown/splitMarkdownIntoSections.d.ts +12 -0
- package/umd/typings/src/utils/markdown/splitMarkdownIntoSections.test.d.ts +1 -0
- package/umd/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +8 -1
- package/umd/typings/src/utils/normalization/normalizeTo_PascalCase.d.ts +8 -1
- package/umd/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +13 -1
- package/umd/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +8 -1
- package/umd/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +8 -1
- package/umd/typings/src/{conversion/utils → utils}/parseNumber.d.ts +1 -1
- package/umd/typings/src/utils/parseNumber.test.d.ts +1 -0
- package/umd/typings/src/utils/sets/difference.d.ts +2 -0
- package/umd/typings/src/utils/sets/intersection.d.ts +2 -0
- package/umd/typings/src/utils/sets/union.d.ts +2 -0
- package/umd/typings/src/utils/validators/email/isValidEmail.d.ts +5 -0
- package/umd/typings/src/utils/validators/email/isValidEmail.test.d.ts +1 -0
- package/umd/typings/src/utils/validators/filePath/isValidFilePath.d.ts +7 -0
- package/umd/typings/src/utils/validators/filePath/isValidFilePath.test.d.ts +1 -0
- package/umd/typings/src/utils/validators/javascriptName/isValidJavascriptName.d.ts +2 -0
- package/umd/typings/src/utils/validators/javascriptName/isValidJavascriptName.test.d.ts +1 -0
- package/umd/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.d.ts +12 -0
- package/umd/typings/src/utils/validators/semanticVersion/isValidPromptbookVersion.test.d.ts +1 -0
- package/umd/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.d.ts +9 -0
- package/umd/typings/src/utils/validators/semanticVersion/isValidSemanticVersion.test.d.ts +1 -0
- package/umd/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.d.ts +9 -0
- package/umd/typings/src/utils/validators/url/isHostnameOnPrivateNetwork.test.d.ts +1 -0
- package/umd/typings/src/utils/validators/url/isUrlOnPrivateNetwork.d.ts +12 -0
- package/umd/typings/src/utils/validators/url/isUrlOnPrivateNetwork.test.d.ts +1 -0
- package/umd/typings/src/utils/validators/url/isValidPipelineUrl.d.ts +12 -0
- package/umd/typings/src/utils/validators/url/isValidPipelineUrl.test.d.ts +1 -0
- package/umd/typings/src/utils/validators/url/isValidUrl.d.ts +3 -0
- package/umd/typings/src/utils/validators/uuid/isValidUuid.d.ts +5 -0
- package/umd/typings/src/utils/validators/uuid/isValidUuid.test.d.ts +1 -0
- package/umd/typings/src/version.d.ts +3 -2
- package/esm/typings/src/cli/actions/hello.d.ts +0 -7
- package/esm/typings/src/cli/actions/make.d.ts +0 -7
- package/esm/typings/src/cli/actions/prettify.d.ts +0 -7
- package/esm/typings/src/conversion/utils/parseCommand.d.ts +0 -11
- package/esm/typings/src/conversion/utils/parseCommand.test.d.ts +0 -4
- package/esm/typings/src/errors/TemplateError.d.ts +0 -9
- package/esm/typings/src/llm-providers/mocked/mocked-chat.test.d.ts +0 -4
- package/esm/typings/src/llm-providers/multiple/MultipleLlmExecutionToolsOptions.d.ts +0 -24
- package/esm/typings/src/types/Command.d.ts +0 -101
- package/esm/typings/src/types/ExecutionTypes.d.ts +0 -13
- package/esm/typings/src/utils/markdown-json/MarkdownStructure.d.ts +0 -25
- package/esm/typings/src/utils/markdown-json/countMarkdownStructureDeepness.d.ts +0 -7
- package/esm/typings/src/utils/markdown-json/markdownToMarkdownStructure.d.ts +0 -13
- package/umd/typings/src/cli/actions/hello.d.ts +0 -7
- package/umd/typings/src/cli/actions/make.d.ts +0 -7
- package/umd/typings/src/cli/actions/prettify.d.ts +0 -7
- package/umd/typings/src/conversion/utils/parseCommand.d.ts +0 -11
- package/umd/typings/src/conversion/utils/parseCommand.test.d.ts +0 -4
- package/umd/typings/src/errors/TemplateError.d.ts +0 -9
- package/umd/typings/src/llm-providers/mocked/mocked-chat.test.d.ts +0 -4
- package/umd/typings/src/llm-providers/multiple/MultipleLlmExecutionToolsOptions.d.ts +0 -24
- package/umd/typings/src/types/Command.d.ts +0 -101
- package/umd/typings/src/types/ExecutionTypes.d.ts +0 -13
- package/umd/typings/src/utils/markdown-json/MarkdownStructure.d.ts +0 -25
- package/umd/typings/src/utils/markdown-json/countMarkdownStructureDeepness.d.ts +0 -7
- package/umd/typings/src/utils/markdown-json/markdownToMarkdownStructure.d.ts +0 -13
- /package/esm/typings/src/{conversion/utils/parseNumber.test.d.ts → commands/BLOCK/blockCommand.test.d.ts} +0 -0
- /package/esm/typings/src/{llm-providers/mocked/fakeTextToExpectations.test.d.ts → commands/EXPECT/expectCommand.test.d.ts} +0 -0
- /package/esm/typings/src/{llm-providers/mocked/faked-completion.test.d.ts → commands/JOKER/jokerCommand.test.d.ts} +0 -0
- /package/esm/typings/src/{utils/markdown-json/countMarkdownStructureDeepness.test.d.ts → commands/KNOWLEDGE/knowledgeCommand.test.d.ts} +0 -0
- /package/esm/typings/src/{utils/markdown-json/markdownToMarkdownStructure.test.d.ts → commands/MODEL/modelCommand.test.d.ts} +0 -0
- /package/{umd/typings/src/conversion/utils/parseNumber.test.d.ts → esm/typings/src/commands/PARAMETER/parameterCommand.test.d.ts} +0 -0
- /package/{umd/typings/src/llm-providers/mocked/fakeTextToExpectations.test.d.ts → esm/typings/src/commands/PERSONA/personaCommand.test.d.ts} +0 -0
- /package/{umd/typings/src/llm-providers/mocked/faked-completion.test.d.ts → esm/typings/src/commands/POSTPROCESS/postprocessCommand.test.d.ts} +0 -0
- /package/{umd/typings/src/utils/markdown-json/countMarkdownStructureDeepness.test.d.ts → esm/typings/src/commands/PROMPTBOOK_VERSION/promptbookVersionCommand.test.d.ts} +0 -0
- /package/{umd/typings/src/utils/markdown-json/markdownToMarkdownStructure.test.d.ts → esm/typings/src/commands/URL/urlCommand.test.d.ts} +0 -0
- /package/esm/typings/src/llm-providers/mocked/{joker.test.d.ts → test/joker.test.d.ts} +0 -0
- /package/esm/typings/src/llm-providers/mocked/{mocked-completion.test.d.ts → test/mocked-completion.test.d.ts} +0 -0
- /package/umd/typings/src/llm-providers/mocked/{joker.test.d.ts → test/joker.test.d.ts} +0 -0
- /package/umd/typings/src/llm-providers/mocked/{mocked-completion.test.d.ts → test/mocked-completion.test.d.ts} +0 -0
package/esm/index.es.js
CHANGED
|
@@ -134,16 +134,15 @@ var UnexpectedError = /** @class */ (function (_super) {
|
|
|
134
134
|
return UnexpectedError;
|
|
135
135
|
}(Error));
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
function normalizeTo_camelCase(sentence, __firstLetterCapital) {
|
|
137
|
+
function normalizeTo_camelCase(text, _isFirstLetterCapital) {
|
|
139
138
|
var e_1, _a;
|
|
140
|
-
if (
|
|
139
|
+
if (_isFirstLetterCapital === void 0) { _isFirstLetterCapital = false; }
|
|
141
140
|
var charType;
|
|
142
141
|
var lastCharType = null;
|
|
143
142
|
var normalizedName = '';
|
|
144
143
|
try {
|
|
145
|
-
for (var
|
|
146
|
-
var char =
|
|
144
|
+
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
145
|
+
var char = text_1_1.value;
|
|
147
146
|
var normalizedChar = void 0;
|
|
148
147
|
if (/^[a-z]$/.test(char)) {
|
|
149
148
|
charType = 'LOWERCASE';
|
|
@@ -162,7 +161,7 @@ function normalizeTo_camelCase(sentence, __firstLetterCapital) {
|
|
|
162
161
|
normalizedChar = '';
|
|
163
162
|
}
|
|
164
163
|
if (!lastCharType) {
|
|
165
|
-
if (
|
|
164
|
+
if (_isFirstLetterCapital) {
|
|
166
165
|
normalizedChar = normalizedChar.toUpperCase(); //TODO: DRY
|
|
167
166
|
}
|
|
168
167
|
}
|
|
@@ -179,7 +178,7 @@ function normalizeTo_camelCase(sentence, __firstLetterCapital) {
|
|
|
179
178
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
180
179
|
finally {
|
|
181
180
|
try {
|
|
182
|
-
if (
|
|
181
|
+
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
183
182
|
}
|
|
184
183
|
finally { if (e_1) throw e_1.error; }
|
|
185
184
|
}
|
|
@@ -441,16 +440,15 @@ function removeDiacritics(input) {
|
|
|
441
440
|
});
|
|
442
441
|
}
|
|
443
442
|
|
|
444
|
-
|
|
445
|
-
function normalizeToKebabCase(sentence) {
|
|
443
|
+
function normalizeToKebabCase(text) {
|
|
446
444
|
var e_1, _a;
|
|
447
|
-
|
|
445
|
+
text = removeDiacritics(text);
|
|
448
446
|
var charType;
|
|
449
447
|
var lastCharType = 'OTHER';
|
|
450
448
|
var normalizedName = '';
|
|
451
449
|
try {
|
|
452
|
-
for (var
|
|
453
|
-
var char =
|
|
450
|
+
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
451
|
+
var char = text_1_1.value;
|
|
454
452
|
var normalizedChar = void 0;
|
|
455
453
|
if (/^[a-z]$/.test(char)) {
|
|
456
454
|
charType = 'LOWERCASE';
|
|
@@ -485,7 +483,7 @@ function normalizeToKebabCase(sentence) {
|
|
|
485
483
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
486
484
|
finally {
|
|
487
485
|
try {
|
|
488
|
-
if (
|
|
486
|
+
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
489
487
|
}
|
|
490
488
|
finally { if (e_1) throw e_1.error; }
|
|
491
489
|
}
|
|
@@ -609,15 +607,15 @@ function extractParameters(template) {
|
|
|
609
607
|
/**
|
|
610
608
|
* This error indicates that the promptbook in a markdown format cannot be parsed into a valid promptbook object
|
|
611
609
|
*/
|
|
612
|
-
var
|
|
613
|
-
__extends(
|
|
614
|
-
function
|
|
610
|
+
var ParsingError = /** @class */ (function (_super) {
|
|
611
|
+
__extends(ParsingError, _super);
|
|
612
|
+
function ParsingError(message) {
|
|
615
613
|
var _this = _super.call(this, message) || this;
|
|
616
|
-
_this.name = '
|
|
617
|
-
Object.setPrototypeOf(_this,
|
|
614
|
+
_this.name = 'ParsingError';
|
|
615
|
+
Object.setPrototypeOf(_this, ParsingError.prototype);
|
|
618
616
|
return _this;
|
|
619
617
|
}
|
|
620
|
-
return
|
|
618
|
+
return ParsingError;
|
|
621
619
|
}(Error));
|
|
622
620
|
|
|
623
621
|
/**
|
|
@@ -625,7 +623,7 @@ var SyntaxError = /** @class */ (function (_super) {
|
|
|
625
623
|
*
|
|
626
624
|
* @param script from which to extract the variables
|
|
627
625
|
* @returns the list of variable names
|
|
628
|
-
* @throws {
|
|
626
|
+
* @throws {ParsingError} if the script is invalid
|
|
629
627
|
*/
|
|
630
628
|
function extractVariables(script) {
|
|
631
629
|
var variables = new Set();
|
|
@@ -641,9 +639,8 @@ function extractVariables(script) {
|
|
|
641
639
|
}
|
|
642
640
|
var undefinedName = error.message.split(' ')[0];
|
|
643
641
|
/*
|
|
644
|
-
Note:
|
|
645
|
-
|
|
646
|
-
To: [Error: Parameter {thing} is not defined],
|
|
642
|
+
Note: Parsing the error
|
|
643
|
+
[ReferenceError: thing is not defined]
|
|
647
644
|
*/
|
|
648
645
|
if (!undefinedName) {
|
|
649
646
|
throw error;
|
|
@@ -661,7 +658,7 @@ function extractVariables(script) {
|
|
|
661
658
|
if (!(error instanceof Error)) {
|
|
662
659
|
throw error;
|
|
663
660
|
}
|
|
664
|
-
throw new
|
|
661
|
+
throw new ParsingError(spaceTrim(function (block) { return "\n Can not extract variables from the script\n\n ".concat(block(error.name), ": ").concat(block(error.message), "\n "); }));
|
|
665
662
|
}
|
|
666
663
|
return variables;
|
|
667
664
|
}
|
|
@@ -674,7 +671,7 @@ function extractVariables(script) {
|
|
|
674
671
|
*
|
|
675
672
|
* @param promptTemplate the template with used parameters
|
|
676
673
|
* @returns the set of parameter names
|
|
677
|
-
* @throws {
|
|
674
|
+
* @throws {ParsingError} if the script is invalid
|
|
678
675
|
*/
|
|
679
676
|
function extractParametersFromPromptTemplate(promptTemplate) {
|
|
680
677
|
var e_1, _a, e_2, _b;
|
|
@@ -692,7 +689,7 @@ function extractParametersFromPromptTemplate(promptTemplate) {
|
|
|
692
689
|
}
|
|
693
690
|
finally { if (e_1) throw e_1.error; }
|
|
694
691
|
}
|
|
695
|
-
if (promptTemplate.
|
|
692
|
+
if (promptTemplate.blockType === 'SCRIPT') {
|
|
696
693
|
try {
|
|
697
694
|
for (var _e = __values(extractVariables(promptTemplate.content)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
698
695
|
var parameterName = _f.value;
|
|
@@ -713,73 +710,6 @@ function extractParametersFromPromptTemplate(promptTemplate) {
|
|
|
713
710
|
* TODO: [🔣] If script require contentLanguage
|
|
714
711
|
*/
|
|
715
712
|
|
|
716
|
-
/**
|
|
717
|
-
* Function parseNumber will parse number from string
|
|
718
|
-
*
|
|
719
|
-
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
720
|
-
* Note: it also works only with decimal numbers
|
|
721
|
-
*
|
|
722
|
-
* @returns parsed number
|
|
723
|
-
* @throws {SyntaxError} if the value is not a number
|
|
724
|
-
*
|
|
725
|
-
* @private within the parseCommand
|
|
726
|
-
*/
|
|
727
|
-
function parseNumber(value) {
|
|
728
|
-
var originalValue = value;
|
|
729
|
-
if (typeof value === 'number') {
|
|
730
|
-
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
731
|
-
}
|
|
732
|
-
if (typeof value !== 'string') {
|
|
733
|
-
return 0;
|
|
734
|
-
}
|
|
735
|
-
value = value.trim();
|
|
736
|
-
if (value.startsWith('+')) {
|
|
737
|
-
return parseNumber(value.substring(1));
|
|
738
|
-
}
|
|
739
|
-
if (value.startsWith('-')) {
|
|
740
|
-
var number = parseNumber(value.substring(1));
|
|
741
|
-
if (number === 0) {
|
|
742
|
-
return 0; // <- Note: To prevent -0
|
|
743
|
-
}
|
|
744
|
-
return -number;
|
|
745
|
-
}
|
|
746
|
-
value = value.replace(/,/g, '.');
|
|
747
|
-
value = value.toUpperCase();
|
|
748
|
-
if (value === '') {
|
|
749
|
-
return 0;
|
|
750
|
-
}
|
|
751
|
-
if (value === '♾' || value.startsWith('INF')) {
|
|
752
|
-
return Infinity;
|
|
753
|
-
}
|
|
754
|
-
if (value.includes('/')) {
|
|
755
|
-
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
756
|
-
var numerator = parseNumber(numerator_);
|
|
757
|
-
var denominator = parseNumber(denominator_);
|
|
758
|
-
if (denominator === 0) {
|
|
759
|
-
throw new SyntaxError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
760
|
-
}
|
|
761
|
-
return numerator / denominator;
|
|
762
|
-
}
|
|
763
|
-
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
764
|
-
return 0;
|
|
765
|
-
}
|
|
766
|
-
if (value.includes('E')) {
|
|
767
|
-
var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
|
|
768
|
-
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
769
|
-
}
|
|
770
|
-
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
771
|
-
throw new SyntaxError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
772
|
-
}
|
|
773
|
-
var num = parseFloat(value);
|
|
774
|
-
if (isNaN(num)) {
|
|
775
|
-
throw new SyntaxError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
776
|
-
}
|
|
777
|
-
return num;
|
|
778
|
-
}
|
|
779
|
-
/**
|
|
780
|
-
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
781
|
-
*/
|
|
782
|
-
|
|
783
713
|
/**
|
|
784
714
|
* This error indicates that the promptbook object has valid syntax but contains logical errors (like circular dependencies)
|
|
785
715
|
*/
|
|
@@ -930,19 +860,17 @@ function forEachAsync(array, options, callbackfunction) {
|
|
|
930
860
|
var LOOP_LIMIT = 1000;
|
|
931
861
|
|
|
932
862
|
/**
|
|
933
|
-
* This error
|
|
934
|
-
*
|
|
935
|
-
* Note: This is a kindof subtype of ExecutionError because it occurs during the execution of the pipeline
|
|
863
|
+
* This error indicates errors during the execution of the pipeline
|
|
936
864
|
*/
|
|
937
|
-
var
|
|
938
|
-
__extends(
|
|
939
|
-
function
|
|
865
|
+
var PipelineExecutionError = /** @class */ (function (_super) {
|
|
866
|
+
__extends(PipelineExecutionError, _super);
|
|
867
|
+
function PipelineExecutionError(message) {
|
|
940
868
|
var _this = _super.call(this, message) || this;
|
|
941
|
-
_this.name = '
|
|
942
|
-
Object.setPrototypeOf(_this,
|
|
869
|
+
_this.name = 'PipelineExecutionError';
|
|
870
|
+
Object.setPrototypeOf(_this, PipelineExecutionError.prototype);
|
|
943
871
|
return _this;
|
|
944
872
|
}
|
|
945
|
-
return
|
|
873
|
+
return PipelineExecutionError;
|
|
946
874
|
}(Error));
|
|
947
875
|
|
|
948
876
|
/**
|
|
@@ -951,7 +879,7 @@ var TemplateError = /** @class */ (function (_super) {
|
|
|
951
879
|
* @param template the template with parameters in {curly} braces
|
|
952
880
|
* @param parameters the object with parameters
|
|
953
881
|
* @returns the template with replaced parameters
|
|
954
|
-
* @throws {
|
|
882
|
+
* @throws {PipelineExecutionError} if parameter is not defined, not closed, or not opened
|
|
955
883
|
*
|
|
956
884
|
* @private within the createPipelineExecutor
|
|
957
885
|
*/
|
|
@@ -969,14 +897,14 @@ function replaceParameters(template, parameters) {
|
|
|
969
897
|
return "continue";
|
|
970
898
|
}
|
|
971
899
|
if (parameterName.indexOf('{') !== -1 || parameterName.indexOf('}') !== -1) {
|
|
972
|
-
throw new
|
|
900
|
+
throw new PipelineExecutionError('Parameter is already opened or not closed');
|
|
973
901
|
}
|
|
974
902
|
if (parameters[parameterName] === undefined) {
|
|
975
|
-
throw new
|
|
903
|
+
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
976
904
|
}
|
|
977
905
|
var parameterValue = parameters[parameterName];
|
|
978
906
|
if (parameterValue === undefined) {
|
|
979
|
-
throw new
|
|
907
|
+
throw new PipelineExecutionError("Parameter {".concat(parameterName, "} is not defined"));
|
|
980
908
|
}
|
|
981
909
|
parameterValue = parameterValue.toString();
|
|
982
910
|
if (parameterValue.includes('\n') && /^\s*\W{0,3}\s*$/.test(precol)) {
|
|
@@ -996,11 +924,11 @@ function replaceParameters(template, parameters) {
|
|
|
996
924
|
}
|
|
997
925
|
// [💫] Check if there are parameters that are not closed properly
|
|
998
926
|
if (/{\w+$/.test(replacedTemplate)) {
|
|
999
|
-
throw new
|
|
927
|
+
throw new PipelineExecutionError('Parameter is not closed');
|
|
1000
928
|
}
|
|
1001
929
|
// [💫] Check if there are parameters that are not opened properly
|
|
1002
930
|
if (/^\w+}/.test(replacedTemplate)) {
|
|
1003
|
-
throw new
|
|
931
|
+
throw new PipelineExecutionError('Parameter is not opened');
|
|
1004
932
|
}
|
|
1005
933
|
return replacedTemplate;
|
|
1006
934
|
}
|
|
@@ -1106,152 +1034,6 @@ function capitalize(word) {
|
|
|
1106
1034
|
return word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
1107
1035
|
}
|
|
1108
1036
|
|
|
1109
|
-
/**
|
|
1110
|
-
* Extracts all code blocks from markdown.
|
|
1111
|
-
*
|
|
1112
|
-
* Note: There are 3 simmilar function:
|
|
1113
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
1114
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
1115
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
1116
|
-
*
|
|
1117
|
-
* @param markdown any valid markdown
|
|
1118
|
-
* @returns code blocks with language and content
|
|
1119
|
-
*
|
|
1120
|
-
*/
|
|
1121
|
-
function extractAllBlocksFromMarkdown(markdown) {
|
|
1122
|
-
var e_1, _a;
|
|
1123
|
-
var codeBlocks = [];
|
|
1124
|
-
var lines = markdown.split('\n');
|
|
1125
|
-
var currentCodeBlock = null;
|
|
1126
|
-
try {
|
|
1127
|
-
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
1128
|
-
var line = lines_1_1.value;
|
|
1129
|
-
if (line.startsWith('```')) {
|
|
1130
|
-
var language = line.slice(3).trim() || null;
|
|
1131
|
-
if (currentCodeBlock === null) {
|
|
1132
|
-
currentCodeBlock = { language: language, content: '' };
|
|
1133
|
-
}
|
|
1134
|
-
else {
|
|
1135
|
-
if (language !== null) {
|
|
1136
|
-
// [🌻]
|
|
1137
|
-
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
1138
|
-
}
|
|
1139
|
-
codeBlocks.push(currentCodeBlock);
|
|
1140
|
-
currentCodeBlock = null;
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
else if (currentCodeBlock !== null) {
|
|
1144
|
-
if (currentCodeBlock.content !== '') {
|
|
1145
|
-
currentCodeBlock.content += '\n';
|
|
1146
|
-
}
|
|
1147
|
-
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1152
|
-
finally {
|
|
1153
|
-
try {
|
|
1154
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
1155
|
-
}
|
|
1156
|
-
finally { if (e_1) throw e_1.error; }
|
|
1157
|
-
}
|
|
1158
|
-
if (currentCodeBlock !== null) {
|
|
1159
|
-
// [🌻]
|
|
1160
|
-
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
1161
|
-
}
|
|
1162
|
-
return codeBlocks;
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
/**
|
|
1166
|
-
* Utility function to extract all list items from markdown
|
|
1167
|
-
*
|
|
1168
|
-
* Note: It works with both ul and ol
|
|
1169
|
-
* Note: It omits list items in code blocks
|
|
1170
|
-
* Note: It flattens nested lists
|
|
1171
|
-
* Note: It can not work with html syntax and comments
|
|
1172
|
-
*
|
|
1173
|
-
* @param markdown any valid markdown
|
|
1174
|
-
* @returns
|
|
1175
|
-
*/
|
|
1176
|
-
function extractAllListItemsFromMarkdown(markdown) {
|
|
1177
|
-
var e_1, _a;
|
|
1178
|
-
var lines = markdown.split('\n');
|
|
1179
|
-
var listItems = [];
|
|
1180
|
-
var isInCodeBlock = false;
|
|
1181
|
-
try {
|
|
1182
|
-
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
1183
|
-
var line = lines_1_1.value;
|
|
1184
|
-
var trimmedLine = line.trim();
|
|
1185
|
-
if (trimmedLine.startsWith('```')) {
|
|
1186
|
-
isInCodeBlock = !isInCodeBlock;
|
|
1187
|
-
}
|
|
1188
|
-
if (!isInCodeBlock && (trimmedLine.startsWith('-') || trimmedLine.match(/^\d+\./))) {
|
|
1189
|
-
var listItem = trimmedLine.replace(/^-|\d+\./, '').trim();
|
|
1190
|
-
listItems.push(listItem);
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1195
|
-
finally {
|
|
1196
|
-
try {
|
|
1197
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
1198
|
-
}
|
|
1199
|
-
finally { if (e_1) throw e_1.error; }
|
|
1200
|
-
}
|
|
1201
|
-
return listItems;
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
/**
|
|
1205
|
-
* Extracts exactly ONE code block from markdown.
|
|
1206
|
-
*
|
|
1207
|
-
* Note: If there are multiple or no code blocks the function throws an error
|
|
1208
|
-
*
|
|
1209
|
-
* Note: There are 3 simmilar function:
|
|
1210
|
-
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
1211
|
-
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
1212
|
-
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
1213
|
-
*
|
|
1214
|
-
* @param markdown any valid markdown
|
|
1215
|
-
* @returns code block with language and content
|
|
1216
|
-
*/
|
|
1217
|
-
function extractOneBlockFromMarkdown(markdown) {
|
|
1218
|
-
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
1219
|
-
if (codeBlocks.length !== 1) {
|
|
1220
|
-
// TODO: Report more specific place where the error happened
|
|
1221
|
-
throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
|
|
1222
|
-
}
|
|
1223
|
-
return codeBlocks[0];
|
|
1224
|
-
}
|
|
1225
|
-
/***
|
|
1226
|
-
* TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
1227
|
-
*/
|
|
1228
|
-
|
|
1229
|
-
/**
|
|
1230
|
-
* Removes HTML or Markdown comments from a string.
|
|
1231
|
-
*
|
|
1232
|
-
* @param {string} content - The string to remove comments from.
|
|
1233
|
-
* @returns {string} The input string with all comments removed.
|
|
1234
|
-
*/
|
|
1235
|
-
function removeContentComments(content) {
|
|
1236
|
-
return spaceTrim(content.replace(/<!--(.*?)-->/gs, ''));
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
|
-
/**
|
|
1240
|
-
* Removes Markdown formatting tags from a string.
|
|
1241
|
-
*
|
|
1242
|
-
* @param {string} str - The string to remove Markdown tags from.
|
|
1243
|
-
* @returns {string} The input string with all Markdown tags removed.
|
|
1244
|
-
*/
|
|
1245
|
-
function removeMarkdownFormatting(str) {
|
|
1246
|
-
// Remove bold formatting
|
|
1247
|
-
str = str.replace(/\*\*(.*?)\*\*/g, '$1');
|
|
1248
|
-
// Remove italic formatting
|
|
1249
|
-
str = str.replace(/\*(.*?)\*/g, '$1');
|
|
1250
|
-
// Remove code formatting
|
|
1251
|
-
str = str.replace(/`(.*?)`/g, '$1');
|
|
1252
|
-
return str;
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
1037
|
/**
|
|
1256
1038
|
* Makes first letter of a string uppercase
|
|
1257
1039
|
*
|
|
@@ -1260,22 +1042,14 @@ function decapitalize(word) {
|
|
|
1260
1042
|
return word.substring(0, 1).toLowerCase() + word.substring(1);
|
|
1261
1043
|
}
|
|
1262
1044
|
|
|
1263
|
-
|
|
1264
|
-
/*
|
|
1265
|
-
TODO: Tests
|
|
1266
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
|
|
1267
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
|
|
1268
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
|
|
1269
|
-
expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
|
|
1270
|
-
*/
|
|
1271
|
-
function normalizeTo_SCREAMING_CASE(sentence) {
|
|
1045
|
+
function normalizeTo_SCREAMING_CASE(text) {
|
|
1272
1046
|
var e_1, _a;
|
|
1273
1047
|
var charType;
|
|
1274
1048
|
var lastCharType = 'OTHER';
|
|
1275
1049
|
var normalizedName = '';
|
|
1276
1050
|
try {
|
|
1277
|
-
for (var
|
|
1278
|
-
var char =
|
|
1051
|
+
for (var text_1 = __values(text), text_1_1 = text_1.next(); !text_1_1.done; text_1_1 = text_1.next()) {
|
|
1052
|
+
var char = text_1_1.value;
|
|
1279
1053
|
var normalizedChar = void 0;
|
|
1280
1054
|
if (/^[a-z]$/.test(char)) {
|
|
1281
1055
|
charType = 'LOWERCASE';
|
|
@@ -1310,7 +1084,7 @@ function normalizeTo_SCREAMING_CASE(sentence) {
|
|
|
1310
1084
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1311
1085
|
finally {
|
|
1312
1086
|
try {
|
|
1313
|
-
if (
|
|
1087
|
+
if (text_1_1 && !text_1_1.done && (_a = text_1.return)) _a.call(text_1);
|
|
1314
1088
|
}
|
|
1315
1089
|
finally { if (e_1) throw e_1.error; }
|
|
1316
1090
|
}
|
|
@@ -1321,6 +1095,11 @@ function normalizeTo_SCREAMING_CASE(sentence) {
|
|
|
1321
1095
|
return normalizedName;
|
|
1322
1096
|
}
|
|
1323
1097
|
/**
|
|
1098
|
+
* TODO: Tests
|
|
1099
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'Moje tabule' })).toEqual('/VtG7sR9rRJqwNEdM2/Moje tabule');
|
|
1100
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: 'ěščřžžýáíúů' })).toEqual('/VtG7sR9rRJqwNEdM2/escrzyaieuu');
|
|
1101
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj');
|
|
1102
|
+
* > expect(encodeRoutePath({ uriId: 'VtG7sR9rRJqwNEdM2', name: ' ahoj_ahojAhoj ahoj ' })).toEqual('/VtG7sR9rRJqwNEdM2/ahoj-ahoj-ahoj-ahoj');
|
|
1324
1103
|
* TODO: [🌺] Use some intermediate util splitWords
|
|
1325
1104
|
*/
|
|
1326
1105
|
|
|
@@ -1370,13 +1149,12 @@ function nameToUriParts(name) {
|
|
|
1370
1149
|
.filter(function (value) { return value !== ''; });
|
|
1371
1150
|
}
|
|
1372
1151
|
|
|
1373
|
-
function normalizeTo_PascalCase(
|
|
1374
|
-
return normalizeTo_camelCase(
|
|
1152
|
+
function normalizeTo_PascalCase(text) {
|
|
1153
|
+
return normalizeTo_camelCase(text, true);
|
|
1375
1154
|
}
|
|
1376
1155
|
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
return normalizeTo_SCREAMING_CASE(sentence).toLowerCase();
|
|
1156
|
+
function normalizeTo_snake_case(text) {
|
|
1157
|
+
return normalizeTo_SCREAMING_CASE(text).toLowerCase();
|
|
1380
1158
|
}
|
|
1381
1159
|
|
|
1382
1160
|
/**
|
|
@@ -1446,6 +1224,154 @@ function searchKeywords(haystack, needle) {
|
|
|
1446
1224
|
return true;
|
|
1447
1225
|
}
|
|
1448
1226
|
|
|
1227
|
+
/**
|
|
1228
|
+
* Function parseNumber will parse number from string
|
|
1229
|
+
*
|
|
1230
|
+
* Unlike Number.parseInt, Number.parseFloat it will never ever result in NaN
|
|
1231
|
+
* Note: it also works only with decimal numbers
|
|
1232
|
+
*
|
|
1233
|
+
* @returns parsed number
|
|
1234
|
+
* @throws {ParsingError} if the value is not a number
|
|
1235
|
+
*
|
|
1236
|
+
* @private within the parseCommand
|
|
1237
|
+
*/
|
|
1238
|
+
function parseNumber(value) {
|
|
1239
|
+
var originalValue = value;
|
|
1240
|
+
if (typeof value === 'number') {
|
|
1241
|
+
value = value.toString(); // <- TODO: Maybe more efficient way to do this
|
|
1242
|
+
}
|
|
1243
|
+
if (typeof value !== 'string') {
|
|
1244
|
+
return 0;
|
|
1245
|
+
}
|
|
1246
|
+
value = value.trim();
|
|
1247
|
+
if (value.startsWith('+')) {
|
|
1248
|
+
return parseNumber(value.substring(1));
|
|
1249
|
+
}
|
|
1250
|
+
if (value.startsWith('-')) {
|
|
1251
|
+
var number = parseNumber(value.substring(1));
|
|
1252
|
+
if (number === 0) {
|
|
1253
|
+
return 0; // <- Note: To prevent -0
|
|
1254
|
+
}
|
|
1255
|
+
return -number;
|
|
1256
|
+
}
|
|
1257
|
+
value = value.replace(/,/g, '.');
|
|
1258
|
+
value = value.toUpperCase();
|
|
1259
|
+
if (value === '') {
|
|
1260
|
+
return 0;
|
|
1261
|
+
}
|
|
1262
|
+
if (value === '♾' || value.startsWith('INF')) {
|
|
1263
|
+
return Infinity;
|
|
1264
|
+
}
|
|
1265
|
+
if (value.includes('/')) {
|
|
1266
|
+
var _a = __read(value.split('/'), 2), numerator_ = _a[0], denominator_ = _a[1];
|
|
1267
|
+
var numerator = parseNumber(numerator_);
|
|
1268
|
+
var denominator = parseNumber(denominator_);
|
|
1269
|
+
if (denominator === 0) {
|
|
1270
|
+
throw new ParsingError("Unable to parse number from \"".concat(originalValue, "\" because denominator is zero"));
|
|
1271
|
+
}
|
|
1272
|
+
return numerator / denominator;
|
|
1273
|
+
}
|
|
1274
|
+
if (/^(NAN|NULL|NONE|UNDEFINED|ZERO|NO.*)$/.test(value)) {
|
|
1275
|
+
return 0;
|
|
1276
|
+
}
|
|
1277
|
+
if (value.includes('E')) {
|
|
1278
|
+
var _b = __read(value.split('E'), 2), significand = _b[0], exponent = _b[1];
|
|
1279
|
+
return parseNumber(significand) * Math.pow(10, parseNumber(exponent));
|
|
1280
|
+
}
|
|
1281
|
+
if (!/^[0-9.]+$/.test(value) || value.split('.').length > 2) {
|
|
1282
|
+
throw new ParsingError("Unable to parse number from \"".concat(originalValue, "\""));
|
|
1283
|
+
}
|
|
1284
|
+
var num = parseFloat(value);
|
|
1285
|
+
if (isNaN(num)) {
|
|
1286
|
+
throw new ParsingError("Unexpected NaN when parsing number from \"".concat(originalValue, "\""));
|
|
1287
|
+
}
|
|
1288
|
+
return num;
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* TODO: Maybe use sth. like safe-eval in fraction/calculation case @see https://www.npmjs.com/package/safe-eval
|
|
1292
|
+
*/
|
|
1293
|
+
|
|
1294
|
+
/**
|
|
1295
|
+
* Extracts all code blocks from markdown.
|
|
1296
|
+
*
|
|
1297
|
+
* Note: There are 3 simmilar function:
|
|
1298
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
1299
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
1300
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
1301
|
+
*
|
|
1302
|
+
* @param markdown any valid markdown
|
|
1303
|
+
* @returns code blocks with language and content
|
|
1304
|
+
*
|
|
1305
|
+
*/
|
|
1306
|
+
function extractAllBlocksFromMarkdown(markdown) {
|
|
1307
|
+
var e_1, _a;
|
|
1308
|
+
var codeBlocks = [];
|
|
1309
|
+
var lines = markdown.split('\n');
|
|
1310
|
+
var currentCodeBlock = null;
|
|
1311
|
+
try {
|
|
1312
|
+
for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
|
|
1313
|
+
var line = lines_1_1.value;
|
|
1314
|
+
if (line.startsWith('```')) {
|
|
1315
|
+
var language = line.slice(3).trim() || null;
|
|
1316
|
+
if (currentCodeBlock === null) {
|
|
1317
|
+
currentCodeBlock = { language: language, content: '' };
|
|
1318
|
+
}
|
|
1319
|
+
else {
|
|
1320
|
+
if (language !== null) {
|
|
1321
|
+
// [🌻]
|
|
1322
|
+
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed and already opening new ").concat(language, " code block"));
|
|
1323
|
+
}
|
|
1324
|
+
codeBlocks.push(currentCodeBlock);
|
|
1325
|
+
currentCodeBlock = null;
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
else if (currentCodeBlock !== null) {
|
|
1329
|
+
if (currentCodeBlock.content !== '') {
|
|
1330
|
+
currentCodeBlock.content += '\n';
|
|
1331
|
+
}
|
|
1332
|
+
currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make propper unescape */;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1337
|
+
finally {
|
|
1338
|
+
try {
|
|
1339
|
+
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
1340
|
+
}
|
|
1341
|
+
finally { if (e_1) throw e_1.error; }
|
|
1342
|
+
}
|
|
1343
|
+
if (currentCodeBlock !== null) {
|
|
1344
|
+
// [🌻]
|
|
1345
|
+
throw new Error("".concat(capitalize(currentCodeBlock.language || 'the'), " code block was not closed at the end of the markdown"));
|
|
1346
|
+
}
|
|
1347
|
+
return codeBlocks;
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
/**
|
|
1351
|
+
* Extracts exactly ONE code block from markdown.
|
|
1352
|
+
*
|
|
1353
|
+
* Note: If there are multiple or no code blocks the function throws an error
|
|
1354
|
+
*
|
|
1355
|
+
* Note: There are 3 simmilar function:
|
|
1356
|
+
* - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
|
|
1357
|
+
* - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
|
|
1358
|
+
* - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
|
|
1359
|
+
*
|
|
1360
|
+
* @param markdown any valid markdown
|
|
1361
|
+
* @returns code block with language and content
|
|
1362
|
+
*/
|
|
1363
|
+
function extractOneBlockFromMarkdown(markdown) {
|
|
1364
|
+
var codeBlocks = extractAllBlocksFromMarkdown(markdown);
|
|
1365
|
+
if (codeBlocks.length !== 1) {
|
|
1366
|
+
// TODO: Report more specific place where the error happened
|
|
1367
|
+
throw new Error(/* <- [🌻] */ 'There should be exactly one code block in the markdown');
|
|
1368
|
+
}
|
|
1369
|
+
return codeBlocks[0];
|
|
1370
|
+
}
|
|
1371
|
+
/***
|
|
1372
|
+
* TODO: [🍓][🌻] !!! Decide of this is internal util, external util OR validator/postprocessor
|
|
1373
|
+
*/
|
|
1374
|
+
|
|
1449
1375
|
/**
|
|
1450
1376
|
* Extracts code block from markdown.
|
|
1451
1377
|
*
|
|
@@ -1486,6 +1412,8 @@ function removeQuotes(text) {
|
|
|
1486
1412
|
|
|
1487
1413
|
/**
|
|
1488
1414
|
* Create difference set of two sets.
|
|
1415
|
+
*
|
|
1416
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
1489
1417
|
*/
|
|
1490
1418
|
function difference(a, b, isEqual) {
|
|
1491
1419
|
var e_1, _a;
|
|
@@ -1514,6 +1442,8 @@ function difference(a, b, isEqual) {
|
|
|
1514
1442
|
|
|
1515
1443
|
/**
|
|
1516
1444
|
* Creates a new set with all elements that are present in all sets
|
|
1445
|
+
*
|
|
1446
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
1517
1447
|
*/
|
|
1518
1448
|
function intersection() {
|
|
1519
1449
|
var e_1, _a;
|
|
@@ -1551,6 +1481,8 @@ function intersection() {
|
|
|
1551
1481
|
|
|
1552
1482
|
/**
|
|
1553
1483
|
* Creates a new set with all elements that are present in either set
|
|
1484
|
+
*
|
|
1485
|
+
* @deprecated use new javascript set methods instead @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
1554
1486
|
*/
|
|
1555
1487
|
function union() {
|
|
1556
1488
|
var e_1, _a, e_2, _b;
|
|
@@ -1689,10 +1621,196 @@ function unwrapResult(text, options) {
|
|
|
1689
1621
|
* TODO: [🧠] Should this also unwrap the (parenthesis)
|
|
1690
1622
|
*/
|
|
1691
1623
|
|
|
1624
|
+
/**
|
|
1625
|
+
* Tests if given string is valid URL.
|
|
1626
|
+
*
|
|
1627
|
+
* Note: This does not check if the file exists only if the path is valid
|
|
1628
|
+
*/
|
|
1629
|
+
function isValidFilePath(filePath) {
|
|
1630
|
+
if (typeof filePath !== 'string') {
|
|
1631
|
+
return false;
|
|
1632
|
+
}
|
|
1633
|
+
var filePathSlashes = filePath.split('\\').join('/');
|
|
1634
|
+
// Absolute Unix path: /hello.txt
|
|
1635
|
+
if (/^(\/)/i.test(filePathSlashes)) {
|
|
1636
|
+
return true;
|
|
1637
|
+
}
|
|
1638
|
+
// Absolute Windows path: /hello.txt
|
|
1639
|
+
if (/^([A-Z]{1,2}:\/?)\//i.test(filePathSlashes)) {
|
|
1640
|
+
return true;
|
|
1641
|
+
}
|
|
1642
|
+
// Relative path: ./hello.txt
|
|
1643
|
+
if (/^(\.\.?\/)+/i.test(filePathSlashes)) {
|
|
1644
|
+
return true;
|
|
1645
|
+
}
|
|
1646
|
+
return false;
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
function isValidJavascriptName(javascriptName) {
|
|
1650
|
+
if (typeof javascriptName !== 'string') {
|
|
1651
|
+
return false;
|
|
1652
|
+
}
|
|
1653
|
+
return /^[a-zA-Z_$][0-9a-zA-Z_$]*$/i.test(javascriptName);
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
/**
|
|
1657
|
+
* Tests if given string is valid semantic version
|
|
1658
|
+
*
|
|
1659
|
+
* Note: There are two simmilar functions:
|
|
1660
|
+
* - `isValidSemanticVersion` which tests any semantic version
|
|
1661
|
+
* - `isValidPromptbookVersion` *(this one)* which tests just Promptbook versions
|
|
1662
|
+
*/
|
|
1663
|
+
function isValidSemanticVersion(version) {
|
|
1664
|
+
if (typeof version !== 'string') {
|
|
1665
|
+
return false;
|
|
1666
|
+
}
|
|
1667
|
+
if (version.startsWith('0.0.0')) {
|
|
1668
|
+
return false;
|
|
1669
|
+
}
|
|
1670
|
+
return /^\d+\.\d+\.\d+(-\d+)?$/i.test(version);
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
/**
|
|
1674
|
+
* Tests if given string is valid promptbook version
|
|
1675
|
+
* It looks into list of known promptbook versions.
|
|
1676
|
+
*
|
|
1677
|
+
* @see https://www.npmjs.com/package/promptbook?activeTab=versions
|
|
1678
|
+
* Note: When you are using for example promptbook 2.0.0 and there already is promptbook 3.0.0 it don`t know about it.
|
|
1679
|
+
* Note: There are two simmilar functions:
|
|
1680
|
+
* - `isValidSemanticVersion` which tests any semantic version
|
|
1681
|
+
* - `isValidPromptbookVersion` *(this one)* which tests just Promptbook versions
|
|
1682
|
+
*/
|
|
1683
|
+
function isValidPromptbookVersion(version) {
|
|
1684
|
+
if (!isValidSemanticVersion(version)) {
|
|
1685
|
+
return false;
|
|
1686
|
+
}
|
|
1687
|
+
if ( /* version === '1.0.0' || */version === '2.0.0' || version === '3.0.0') {
|
|
1688
|
+
return false;
|
|
1689
|
+
}
|
|
1690
|
+
// <- TODO: !!!! Check isValidPromptbookVersion against PROMPTBOOK_VERSIONS
|
|
1691
|
+
return true;
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1694
|
+
/**
|
|
1695
|
+
* Checks if an URL is reserved for private networks or localhost.
|
|
1696
|
+
*
|
|
1697
|
+
* Note: There are two simmilar functions:
|
|
1698
|
+
* - `isUrlOnPrivateNetwork` which tests full URL
|
|
1699
|
+
* - `isHostnameOnPrivateNetwork` *(this one)* which tests just hostname
|
|
1700
|
+
*/
|
|
1701
|
+
function isHostnameOnPrivateNetwork(hostname) {
|
|
1702
|
+
if (hostname === 'example.com' ||
|
|
1703
|
+
hostname === 'localhost' ||
|
|
1704
|
+
hostname.endsWith('.localhost') ||
|
|
1705
|
+
hostname.endsWith('.local') ||
|
|
1706
|
+
hostname.endsWith('.test') ||
|
|
1707
|
+
hostname === '127.0.0.1' ||
|
|
1708
|
+
hostname === '::1') {
|
|
1709
|
+
return true;
|
|
1710
|
+
}
|
|
1711
|
+
if (hostname.includes(':')) {
|
|
1712
|
+
// IPv6
|
|
1713
|
+
var ipParts = hostname.split(':');
|
|
1714
|
+
return ipParts[0] === 'fc00' || ipParts[0] === 'fd00' || ipParts[0] === 'fe80';
|
|
1715
|
+
}
|
|
1716
|
+
else {
|
|
1717
|
+
// IPv4
|
|
1718
|
+
var ipParts = hostname.split('.').map(function (part) { return Number.parseInt(part, 10); });
|
|
1719
|
+
return (ipParts[0] === 10 ||
|
|
1720
|
+
(ipParts[0] === 172 && ipParts[1] >= 16 && ipParts[1] <= 31) ||
|
|
1721
|
+
(ipParts[0] === 192 && ipParts[1] === 168));
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
/**
|
|
1726
|
+
* Checks if an IP address or hostname is reserved for private networks or localhost.
|
|
1727
|
+
*
|
|
1728
|
+
* Note: There are two simmilar functions:
|
|
1729
|
+
* - `isUrlOnPrivateNetwork` *(this one)* which tests full URL
|
|
1730
|
+
* - `isHostnameOnPrivateNetwork` which tests just hostname
|
|
1731
|
+
*
|
|
1732
|
+
* @param {string} ipAddress - The IP address to check.
|
|
1733
|
+
* @returns {boolean} Returns true if the IP address is reserved for private networks or localhost, otherwise false.
|
|
1734
|
+
*/
|
|
1735
|
+
function isUrlOnPrivateNetwork(url) {
|
|
1736
|
+
if (typeof url === 'string') {
|
|
1737
|
+
url = new URL(url);
|
|
1738
|
+
}
|
|
1739
|
+
return isHostnameOnPrivateNetwork(url.hostname);
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
/**
|
|
1743
|
+
* Tests if given string is valid URL.
|
|
1744
|
+
*
|
|
1745
|
+
* Note: Dataurl are considered perfectly valid.
|
|
1746
|
+
* Note: There are two simmilar functions:
|
|
1747
|
+
* - `isValidUrl` which tests any URL
|
|
1748
|
+
* - `isValidPipelineUrl` *(this one)* which tests just promptbook URL
|
|
1749
|
+
*/
|
|
1750
|
+
function isValidUrl(url) {
|
|
1751
|
+
if (typeof url !== 'string') {
|
|
1752
|
+
return false;
|
|
1753
|
+
}
|
|
1754
|
+
try {
|
|
1755
|
+
if (url.startsWith('blob:')) {
|
|
1756
|
+
url = url.replace(/^blob:/, '');
|
|
1757
|
+
}
|
|
1758
|
+
var urlObject = new URL(url /* because fail is handled */);
|
|
1759
|
+
if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
|
|
1760
|
+
return false;
|
|
1761
|
+
}
|
|
1762
|
+
return true;
|
|
1763
|
+
}
|
|
1764
|
+
catch (error) {
|
|
1765
|
+
return false;
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
/**
|
|
1770
|
+
* Tests if given string is valid pipeline URL URL.
|
|
1771
|
+
*
|
|
1772
|
+
* Note: There are two simmilar functions:
|
|
1773
|
+
* - `isValidUrl` which tests any URL
|
|
1774
|
+
* - `isValidPipelineUrl` *(this one)* which tests just pipeline URL
|
|
1775
|
+
*/
|
|
1776
|
+
function isValidPipelineUrl(url) {
|
|
1777
|
+
if (!isValidUrl(url)) {
|
|
1778
|
+
return false;
|
|
1779
|
+
}
|
|
1780
|
+
if (!url.startsWith('https://')) {
|
|
1781
|
+
return false;
|
|
1782
|
+
}
|
|
1783
|
+
if (!url.endsWith('.ptbk.md')) {
|
|
1784
|
+
return false;
|
|
1785
|
+
}
|
|
1786
|
+
if (url.includes('#')) {
|
|
1787
|
+
// TODO: [🐠]
|
|
1788
|
+
return false;
|
|
1789
|
+
}
|
|
1790
|
+
if (isUrlOnPrivateNetwork(url)) {
|
|
1791
|
+
return false;
|
|
1792
|
+
}
|
|
1793
|
+
return true;
|
|
1794
|
+
}
|
|
1795
|
+
/**
|
|
1796
|
+
* TODO: [🐠] Maybe more info why the URL is invalid
|
|
1797
|
+
*/
|
|
1798
|
+
|
|
1799
|
+
/**
|
|
1800
|
+
* Checks if value is valid uuid
|
|
1801
|
+
*/
|
|
1802
|
+
function isValidUuid(value) {
|
|
1803
|
+
if (typeof value !== 'string') {
|
|
1804
|
+
return false;
|
|
1805
|
+
}
|
|
1806
|
+
return /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i.test(value);
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1692
1809
|
/**
|
|
1693
1810
|
* The version of the Promptbook library
|
|
1694
1811
|
*/
|
|
1695
1812
|
var PROMPTBOOK_VERSION = '0.60.0';
|
|
1813
|
+
// TODO: !!!! List here all the versions and annotate + put into script
|
|
1696
1814
|
|
|
1697
1815
|
// @promptbook/utils
|
|
1698
1816
|
// And the normalization (originally n12 library) utilities:
|
|
@@ -1706,9 +1824,9 @@ var normalizeTo = {
|
|
|
1706
1824
|
'kebab-case': normalizeToKebabCase,
|
|
1707
1825
|
};
|
|
1708
1826
|
/**
|
|
1709
|
-
* TODO: [🧠] Maybe create some indipendent package like
|
|
1827
|
+
* TODO: [🧠] Maybe create some indipendent package like `@promptbook/markdown-utils`
|
|
1710
1828
|
* Note: [🕙] It does not make sence to have simple lower / UPPER case normalization
|
|
1711
1829
|
*/
|
|
1712
1830
|
|
|
1713
|
-
export { CountUtils, DIACRITIC_VARIANTS_LETTERS, PROMPTBOOK_VERSION, capitalize, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, decapitalize, difference,
|
|
1831
|
+
export { CountUtils, DIACRITIC_VARIANTS_LETTERS, PROMPTBOOK_VERSION, capitalize, countCharacters, countLines, countPages, countParagraphs, countSentences, countWords, decapitalize, difference, extractBlock, extractParameters, extractParametersFromPromptTemplate, extractVariables, forEachAsync, intersection, isHostnameOnPrivateNetwork, isUrlOnPrivateNetwork, isValidFilePath, isValidJavascriptName, isValidJsonString, isValidKeyword, isValidPipelineUrl, isValidPromptbookVersion, isValidSemanticVersion, isValidUrl, isValidUuid, nameToUriPart, nameToUriParts, normalizeTo, normalizeToKebabCase, normalizeTo_PascalCase, normalizeTo_SCREAMING_CASE, normalizeTo_camelCase, normalizeTo_snake_case, normalizeWhitespaces, parseKeywords, parseKeywordsFromString, parseNumber, removeDiacritics, removeEmojis, removeQuotes, renameParameter, renderPromptbookMermaid, replaceParameters, searchKeywords, splitIntoSentences, titleToName, trimCodeBlock, trimEndOfCodeBlock, union, unwrapResult };
|
|
1714
1832
|
//# sourceMappingURL=index.es.js.map
|