-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
Split mapper #25
Split mapper #25
Conversation
…um and type aliases, improve documentation. Handling incorrect type param value more explicitly.
# Conflicts: # src/Importer.ts
@lowkeypriority it's nice to see your PR 😸
const factory = (options) => {
const splitMapper = (value) => value.split(options.separator);
splitMapper.separator = (separator) => factory({...options, separator});
return splitMapper;
}
export const splitMapper = factory({separator: ','}); // create default split mapper usage: importer.GetAllItems({
workshet:'Authors',
type: ' list',
columns:[
{key:"fullname", index:1},
{key: "books", index:2, mapper:splitMapper}, // map from `"book1,book2"` to `["book1","book2"]`
{key: "adwards", index:3, mapper:splitMapper.separator(' && ')}, // map from `"2020 Adward && 2019 Adward"` to `["2020 Adward","2019 Adward"]`
]
}); |
ups.. It wasn't expected to close it... It was done automatically after #20 become merged |
@Siemienik thanks for review. I'll try to rewrite mappers to factory Also I'll rename issue – one issue - one PR is food practice :) |
@Siemienik Hello again.
export abstract class Mapper {
private options: object
constructor(options: object) {
this.options = options
}
abstract valueOf(value: string): string | string[]
}
import { Mapper } from "./mapperFactory"
export class SplitMapper extends Mapper {
constructor(options: object) {
super({...options, separator: ','})
}
valueOf(value: string) {
value.split(this.options.separator)
}
separator(separator: string) {
this.options.separator = separator
}
} But this solution is not good at all - it contains TypeGuard bugs and, in my opinion, lacks a good abstraction. Can you help with this? Any advice? |
@lowkeypriority code what I write works: there is only lack of types. As a mappers is used as lambda function matches to: |
type SplitMapper =
ValueMapper<Array<string>> // fulfil mapper behaviour
& {separator: (separator:string) => SplitMapper};` // adding api for customisations |
@lowkeypriority I've just updated the and test for it: I suppose it will be handful for you 😸 |
@lowkeypriority how do you up to? Is any way how can I help you? |
suddenly I have to close this PR because lack of activity here, please open new one if needed |
Description
I've been added split mapper and unit test for it.
Also added a description in README, but I don't know how to write an axample :\
Closes #24
"Roadmap"
splitMapper
mappers/index.ts