2020-01-16 20:01:12 +03:00
|
|
|
import Transform from '@ember-data/serializer/transform';
|
2016-03-03 11:52:27 +03:00
|
|
|
|
2022-02-02 13:40:43 +03:00
|
|
|
export default class TwitterUrlUser extends Transform {
|
2016-03-03 11:52:27 +03:00
|
|
|
deserialize(serialized) {
|
|
|
|
if (serialized) {
|
2021-07-14 17:24:17 +03:00
|
|
|
let [, user] = serialized.match(/@?([^/]*)/) || [];
|
2016-03-03 11:52:27 +03:00
|
|
|
|
|
|
|
return `https://twitter.com/${user}`;
|
|
|
|
}
|
|
|
|
return serialized;
|
2022-02-02 13:40:43 +03:00
|
|
|
}
|
2016-03-03 11:52:27 +03:00
|
|
|
|
|
|
|
serialize(deserialized) {
|
|
|
|
if (deserialized) {
|
2021-07-14 17:24:17 +03:00
|
|
|
let [, user] = deserialized.match(/(?:https:\/\/)(?:twitter\.com)\/(?:#!\/)?@?([^/]*)/) || [];
|
2016-03-03 11:52:27 +03:00
|
|
|
|
|
|
|
return `@${user}`;
|
|
|
|
}
|
|
|
|
return deserialized;
|
|
|
|
}
|
2022-02-02 13:40:43 +03:00
|
|
|
}
|