Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More functional presets #21

Open
kwaa opened this issue Nov 20, 2023 · 0 comments
Open

More functional presets #21

kwaa opened this issue Nov 20, 2023 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@kwaa
Copy link
Member

kwaa commented Nov 20, 2023

Currently, the FFF preset looks like this:

import type { FFFTransformPreset } from 'fff-flavored-frontmatter'

// input:
// date: 2023-02-23
// output:
// date: 2023-02-23
// created: 2023-02-23
const basic: FFFTransformPreset = {
  created: 'date',
}

However, it would be nice to be able to rename/remove keys:

type FFFPreset<T extends Record<string, unknown> = Record<string, unknown>>
  = (fm: FFFFlavoredFrontmatter & T) => FFFFlavoredFrontmatter & T

The new preset will provide and accept the full Frontmatter.

Then you can do this:

const rename = (obj: Record<string, string>): FFFPreset => (fm) =>
  Object.fromEntries(
    Object.entries(fm)
      .map(([key, value]) =>
        Object.keys(obj).includes(key)
          ? (Object.keys(fm).includes(obj[key])
            ? [undefined, undefined]
            : [obj[key], value])
          : [key, value],
      ),
  )

const remove = (arr: string[]): FFFPreset => (fm) =>
  Object.fromEntries(
    Object.entries(fm)
      .filter(([key]) => arr.includes(key))
    )
  )
@kwaa kwaa added this to the 2.0 milestone Nov 20, 2023
@kwaa kwaa added the enhancement New feature or request label Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant